Recommended build system for latex?

LatexMakefile

Latex Problem Overview


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?

Latex Solutions


Solution 1 - Latex

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.

Solution 2 - Latex

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.

Solution 3 - Latex

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

Solution 4 - Latex

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/

Solution 5 - Latex

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.

Solution 6 - Latex

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!

Solution 7 - Latex

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).

Solution 8 - Latex

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.

Solution 9 - Latex

(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.

Solution 10 - Latex

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.

Solution 11 - Latex

"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...

Solution 12 - Latex

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.

Solution 13 - Latex

I'm using MikTeX in combination with http://www.texniccenter.org/">TeXnicCenter</a>;. 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.

Solution 14 - Latex

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).

Solution 15 - Latex

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPaul BiggarView Question on Stackoverflow
Solution 1 - LatexPaul BiggarView Answer on Stackoverflow
Solution 2 - LatexagentofuserView Answer on Stackoverflow
Solution 3 - LatexPaul BiggarView Answer on Stackoverflow
Solution 4 - LatexAlmostSureView Answer on Stackoverflow
Solution 5 - LatexThierryView Answer on Stackoverflow
Solution 6 - LatexOlivier VerdierView Answer on Stackoverflow
Solution 7 - LatexPaul BiggarView Answer on Stackoverflow
Solution 8 - LatexKonrad RudolphView Answer on Stackoverflow
Solution 9 - LatexPaul BiggarView Answer on Stackoverflow
Solution 10 - LatexmhbView Answer on Stackoverflow
Solution 11 - LatexMicaView Answer on Stackoverflow
Solution 12 - LatexPaul BiggarView Answer on Stackoverflow
Solution 13 - LatexMartijnView Answer on Stackoverflow
Solution 14 - LatexPaul BiggarView Answer on Stackoverflow
Solution 15 - Latexsorush-rView Answer on Stackoverflow