54

I'm trying to figure out the best build system for latex.

Currently, I use latex-makefile, editing in vim, and viewing changes in Okular or gv. The major problem is that it sometimes gets hides errors on me, and I have to run latex manually. The major advantages are that it does all the iteration I need, and offers both pdf and ps simply.

If you have experience with

  • latex-mk
  • vim-latex
  • kile
  • lyx
  • miktex
  • latex-makefile
  • the ultimate latex makefile
  • rubber
  • any others I havent come across

Would you recommend them, and why/why not?

5
  • 19
    I see a vote to close as 'Not programming related'. It seems to be fairly established that latex questions are appropriate here. A build system question is, if anything, more appropriate to programming than other latex questions. Aug 6, 2009 at 17:21
  • 2
    I like latexmk, I run it with MacTeX. It runs latex enough times to get the cross refs. right, takes care of bibtex, and makeindex as well. Miktex is mostly for windows, so its probably not applicable to you, but there is a beta for it on linux. lyx is wysiwyg for tex, I never liked it b/c i'm comfortable working with the source. Kile is a pretty nice graphical front end for KDE, though I don't use most of the buttons... so it's a bit pointless. :)
    – Mica
    Aug 6, 2009 at 17:56
  • 14
    LaTeX is Turing complete, and dependency controlling build systems are a programming concern. This stuff belongs here and no mistake. Aug 6, 2009 at 18:19
  • 5
    You can find an entire community on the TeX StackExchange, where no TeX-related question is too small. See for instance this question Nov 29, 2010 at 13:15
  • See also tex.stackexchange.com/questions/40738/…
    – koppor
    Sep 24, 2015 at 9:03

15 Answers 15

24

I've just tried out latexmk. If you do

latexmk -pvc file.tex 

Then it will auto preview (DVI by default).

  • Handles dependencies
  • DVI, ps or pdf
  • Iterates fine.
  • Very configurable, see man latexmk

Downsides:

  • It doesnt condense errors, which isnt hugely useful (workaround: use rubber-info separately)
  • Bug in the man file: "Sometimes a viewer (gv) tries to read an updated .ps or .pdf file after its creation is started but before the file is complete. Work around: manually refresh (or reopen) display.". It would be better if it built it via a temporary .pdf file to avoid this.
  • Not hugely user friendly.
4
  • 2
    latexmk doesn’t support XeTeX and there’s apparently no way of changing this short of hacking the hard-coded value of the pdflatex executable. Very annoying. Nov 19, 2009 at 19:52
  • I agree with Paul's answers re: Rubber and Latexmk. I tried Rubber before, it does present build errors nicely, but it's 2-3 years old and doesn't seem that maintained. Latexmk is my current builder of choice. The latest release is from 3 weeks ago, it has quite powerful configuration possibilities (e.g. I have it automatically generate PDF figures from the OmniGraffle files), maybe XeTeX support in even on the author's todo list? Feb 8, 2010 at 14:21
  • 6
    FWIW, Latexmk works just fine with XeTeX now.
    – bcat
    May 19, 2011 at 16:29
  • 1
    if using vim, checkout latex-box
    – ivotron
    Oct 24, 2011 at 7:28
10

After considering all these options for some time, I have settled with the following solution.

  • Set vim to write continuously as I type.
  • Run a script in the background to build continuously, refreshing the pdf as it goes. latexmk is nearly good enough, except that it builds in place, which gets reloaded at a bad time in okular (my viewer).

The script is available at https://github.com/pbiggar/texbuild.

Use rubber-info to get the errors and warnings from the log file. The script above saves the log file in t.log. In vim:

autocmd FileType tex set makeprg=rubber-info\ t.log
autocmd FileType tex set errorformat=%f:%l:\ %m
4
  • Could you post your code again. It's quite weirdly formated as some is in code blocks, and some are not. Meanwhile, some are in headlines etc.
    – martiert
    Jul 29, 2010 at 7:38
  • @martiert: I posted it a few times, and I think I got it right at the end (works for me). Is it OK for you now? Jul 29, 2010 at 8:26
  • @PaulBiggar I know this thread has been dead for a while now but I hope you see this. How do I use your script? I don't know Python or Vim very well and there doesn't seem to be any documentation on how to get it to work.
    – nullUser
    Aug 11, 2012 at 14:06
  • I ran into similar scenarios when "pdflatex" from my windows cmd prompt takes too long and I have to wait. I did try your code with Python, though I did not use Vim. Later, I realize the build system in Sublime (ctrl B) does what I want: I am using Sublime + Latexing plug in + sumatraPDF (for not locking the pdf). If a compile fails, the pdf won't go corrupted, which I think is what you are after. For me, hitting ctrl S + ctrl B once in a while isn't interrupting. And I like the fact that when the compile fails, I can see error msgs in a somewhat informative dialog box.
    – Ying Zhang
    Nov 9, 2018 at 2:03
10

I haven't used it myself, but I've heard of Rubber as a good alternative.

From their website:

Rubber is a program whose purpose is to handle all tasks related to the compilation of LaTeX documents. This includes compiling the document itself, of course, enough times so that all references are defined, and running BibTeX to manage bibliographic references. Automatic execution of dvips to produce PostScript documents is also included, as well as usage of pdfLaTeX to produce PDF documents.

2
  • I tried this before, and I don't remember what problems I had that made me look elsewhere. I just tried it now and it seems to work very well. Thanks. Aug 6, 2009 at 17:05
  • I moved my comments about rubber into their own answer: stackoverflow.com/questions/1240037/… Aug 24, 2009 at 11:46
9

Ok, so this question is a bit old, but it came up when I googled "latex build system" so I thought I'd add my two cents. I tried the Makefile based solutions, but found the output a bit verbose and unwieldy. I figured someone might have built a scons extension for latex, but was pleasantly surprised to find that scons already natively supports latex! All you need to do is create a SConsctruct file like this:

env = Environment()  
env.PDF(target="report.pdf", source="report.tex")

To build just run scons report.pdf. Scons will automatically build .tex files included by report.tex, handle bibliographies and perform repeated builds in order to resolve all references - simple!

You can create DVI and PS files in the same way. For more info on these builders check out http://www.scons.org/doc/2.0.1/HTML/scons-user/a8524.html .

For more info on scons (a make replacement), see http://www.scons.org/

2
  • This is great, especially because you can pass in PDFLATEXFLAGS, which is not possible with rubber. Did you find a way to make the build output less verbose though? Oct 8, 2012 at 19:45
  • Scone also has built in dependency scanning which is nice. You don’t have to explicitly tell it about included files or index’s or the like. Nov 25, 2018 at 18:12
6

I posted a detailed answer using Scons on tex.stackexchange.

Basically, you put this in a file called SConstruct:

# make sure scons finds tex executables:
import os
env = Environment(ENV=os.environ)
# target and source:
pdf_output = env.PDF(target='main.pdf', source='main.tex')
# make sure that the pdf is reloaded properly (e.g., in Skim)
env.Precious(pdf_output)

You can build the pdf simply by running

scons

Amazingly, scons will detect the changes in the files \included in the main.tex file and also the bibliography file!

5

I use Eclipse with the TexEcplise add-on for editing my TeX-files. It has syntax highlight for LaTeX. When you ask a preview of a non-altered and already compiled tex file, it open the file in the viewer. When the tex file was altered, then it compiles the tex file prior to viewing it. It does the necessary iterations, but only if needed.

Another advantage is that all errors and warnings are summarised in a box and they are highlighted in the tex file! This is a screenshot from the TexEclipse homepage.

4

I'm trying rubber for a while. I'll condense the results here:

  • Rubber will automatically convert .eps files into .pdfs for pfdlatex. However, it seems to only do this for includegraphics macros. If you have your own macro, it wont.
  • rubber-info is great, which is magic. It is certainly better than anything else I've seen at getting error message and lines. And you don't actually need to use rubber to build to use it.
  • It doesn't seem to know when to stop iterating, often stopping early.
  • It overwrites your PDF as it builds, which is irritating (it lacks a nice feature from latex-makefile where it builds it in a temp file).
2

I wanted to use the script you posted in your final answer.

Unfortunately, it didn’t work with my setting (MacVim with vim-latexsuite, Skim as the viewer and XeTeX). I also use forward search (i.e. I use the feature that pressing \ls in Vim will jump to the corresponding point in the PDF document in the open viewer).

Furthermore, my document isn’t called thesis.tex (big surprise; it’s not a thesis). I’ve therefore done some more configuration work that I’d like to share. Attention, my bash skills are horrible.

#!/bin/bash

set -x
ulimit -t 10 # sometimes pdflatex gets stuck

if [ "$1" = "" ]; then
    echo "No target name specified"
    exit 1
fi

TARGET=$1
SOURCE=$1.tex
TMPSOURCE=_$TARGET.tex
TMPTARGET=_$TARGET

while [ 1 ]; do
    # Compile a different file ($TMPSOURCE.pdf) so that it doesn't reload mid-compile
    cp $SOURCE $TMPSOURCE
    # better than running pdflatex manually, as this wont rebuild if there's nothing there.
    latexmk -pdf -silent $TMPTARGET > /dev/null

    # For rubber-info
    cp $TMPTARGET.log $TARGET.log

    if [ -e $TMPTARGET.pdf ]; then # Check the compile succeeded first
        # No output file yet.
        [ ! -e $TARGET.pdf ]
        HASNOPDF=$?
        # ignore if it's unchanged.
        # OS X diff doesn't consider binary files. Single-line output, return value 2
        diff $TARGET.pdf $TMPTARGET.pdf
        OUTPUTDIFFERS=$?
        if [ $HASNOPDF -eq 0 -o $OUTPUTDIFFERS -ne 0 ]; then
            # Do NOT RM since Skim cannot deal with this.
            cp $TMPTARGET.pdf $TARGET.pdf
        fi
    fi

    sleep 1 # give it time to be killed by a CTRL-C
done

This compiles a temporary file and copies it back to whatever name was given (instead of the other way round as your script does); usage of the script:

./scriptname project

Where project is the name of the TeX file, without file extension.

I’ve also changed the rubber-info line:

autocmd FileType tex exe "set makeprg=rubber-info\\ _" . expand("%:t:r") . ".log"

And I needed to patch my latexmk to use XeTeX since the name of the executable was hard-coded.

Unfortunately, this still destroys the output PDF file when I’ve saved my document before completing a statement, since latexmk seems to always produce a PDF file, even on error – and its return code is always 0, which sucks.

(To clarify this, say that I’ve just typed emph{ into my document and save it. The background script will promptly compile the document, and fail. But it will still produce a (largely empty) output file).

Additionally, forward search no longer works properly; it basically jumps to a wrong point in the document. I suspect that this has something to do with my copying the document before compilation.

So, this is still a completely unsatisfactory solution, even though I didn’t even enable continuous saving on typing in MacVim yet.

1
  • Actually, I rewrote the script over the last while. I'll post it later. Nov 20, 2009 at 16:36
1

(This is a work in progress)

I'm trying vim-latexsuite at the moment. It basically turns vim into an IDE for latex.

Learning curve:

  • Very unintuitive, but after the tutorial, it seems OK.
  • It redefines some keys I like, and I can't seem to fix them.

Autocomplete:

  • Makes using some built-in macros simpler
  • Adding <<+>> to for user macros is very annoying.
  • Replacing " with `` and the like is nice until you want " for some reason, then its an exercise in frustration.
  • Its autocomplete can be annoying too. I have to reprogram myself for working in latex.

Build system:

  • Awful
  • quickfix doesn't work - it often puts me in the wrong file
  • When latex reports errors with the result split over 2 lines, it doesn't detect it.
2
  • Much the same experience here, but I now use it all the time and it works quite nicely for editing. I like the macros, after some getting used to. Nov 19, 2009 at 19:49
  • Trying to get this thing working with xetex and biblatex. The best I got is three consecutive runs with dependencies. But it was forever! let g:Tex_FormatDependency_pdf = 'bcf,bib,pdf'\n let g:Tex_CompileRule_bcf = 'xelatex --interaction=nonstopmode $*'\n let g:Tex_CompileRule_bib = 'biber -q $*' let g:Tex_CompileRule_pdf = 'xelatex --interaction=nonstopmode $* Mar 8, 2012 at 19:10
1

AUCTEX & preview-latex with Emacs another option.

You can also have emacs open up the resultant dvi, or pdf file, and if you turn auto-revert-mode on for that buffer, the changes will be rendered everytime you recompile the document.

0

"Better" is a very relative term... what else do you want to do? It seems like this makefile handles quite a bit, and it makes me wish I was running a *nix at work instead of windows... if there are more things you need to handle with the makefile, why not add them in?

To make it "better" you would need to provide more details on what exactly you're doing.

For instance, you could have it parse the .log file with grep, search for errors or warnings, dump them into another file, then open the new file so you can read through the errors.

It all depends on what you want to do...

3
  • OK, I've clarified "better" in the question. Aug 6, 2009 at 16:43
  • What is your end goal? "More productive" is still quite relative... If your major headache is errors and having to run latex manually, I might suggest moving away from vim and onto something like Kile, which will spit out errors in the bottom pane... do you have the latex vim plugin? You could tell latex to run in non-stop mode (i.e. not stop on errors) by adding the -r flag to your makefile. Again, it all depends on what you want to do, since latex is pretty flexable. Thus, if you do not have anything really specific in mind, you probably are not going to get great answers :D
    – Mica
    Aug 6, 2009 at 17:20
  • Mica S.: I'm trying to get suggestions as to potentially better ways to do it. I'll clarify better. Aug 6, 2009 at 17:33
0

I'm using MikTeX in combination with TeXnicCenter. It works fine for my purposes. I've never ever had the system hiding errors or warnings. Custom build scripts are easy to create and configure.

2
  • Nope, seems to be windows only
    – Martijn
    Sep 9, 2009 at 6:42
  • TexMaker is all you want/need.
    – sjas
    Mar 10, 2013 at 15:47
0

ltx claims to be a wrapper to latex to speed up the compilation of latex documents. I couldn't make it work though (some problems with initex).

1
  • Link is 404 now.
    – koppor
    Jun 17, 2017 at 16:05
0

I've been using the latex-makefile for a while. Its pretty good if you're trying to use an edit-compile-preview cycle:

  • Takes almost zero configuration.
  • Builds .ps or .pdf.
  • Handles all the necessary iteration. I literally have to write nothing else.
  • Quite robust, but occasionally the errors and warnings get mangled.
  • It doesn't kill the old pdf until the new one is built.
  • It builds other files, like generating eps from gnuplot. I havent found this hugely useful though.
  • The author is very quick to respond to feature requests.
  • I can replicate the advantages of latexmk fairly easily with:

    while [ 1 ]; do /usr/bin/make; done
    

Some downsides:

  • It only allows pdf generation via dvi -> ps -> pdf, instead of directly via pdftex.
  • Its error output isnt the same as the standard latex one, so vim isnt moving to the correct line.
  • It doesnt always recompile on changes in bibtex and other non-tex sources.
  • If I remove a file, it doesn't remove the dependency without a make clean.
0

Have a look at TeXMaker. :-)

features (from wiki):

  • In-line spell check.
  • A unicode editor to write LaTeX source files (syntax highlighting, undo-redo, search-replace, spell checker...)
  • LaTeX tags and mathematical symbols can be entered with a mouse
  • Document and section templates
  • LaTeX-related programs can be launched
  • BibTeX database management
  • An outline or "structure view"
  • Logfiles during LaTeX compilation and the ability to "step through" source errors that are discovered by the compiler
  • An integrated LaTeX to HTML conversion tool

features (from me):

  • useful wizards for inserting tables, citation, referencing
  • bidirectional support
  • useful keyboard shortcuts
  • Auto Complete words (specially is useful with referencing)
  • define your own instructions
1
  • Make sure to additionally check out TeXMakerX ( texmakerx.sourceforge.net ) - it's a fork of TeXMaker with some more useful features.
    – Martin Ba
    Sep 3, 2010 at 20:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.