26

Even though I can find this command hiding somewhere on the internet, I though it might be useful to have it up here for the LaTeX community in general.

How does one run TeX from the command line interface (Terminal) in Linux? Are there any required parameters? What if the command is part of a bigger script, how does the script know when the TeX processing is done to continue with any subsequent actions needed? Is there a clear manual for this somewhere?


A starting point might be:

pdflatex [options] filename.tex
latex [options] filename.tex
xelatex [options] filename.tex
5
  • 13
    Hi! In my opinion, your question does not seem to me to be really good. There are couple reasons: (1) You answer the question in the question text. (2) You obviously somehow know the answer and you don't ask "for yourself", but in the current shape, I don't think it can help anybody. (3) Please note that most of the "broad" questions like this one are posted after some discussion in the community, usually on TeX - LaTeX Meta or in chat, in both of which you're most welcome ;) (Notice that I didn't downvote it since I think -1 is enough.)
    – yo'
    Dec 17, 2012 at 9:38
  • 5
    @tohecz I need to mention how much I like what you have done here. Most people do not take the time to comment when they downvote a question. Without even downvoting it you explained very well why you think the question is bad and in such a friendly manner! I wish this happened more often.
    – Vivi
    Dec 17, 2012 at 10:07
  • 3
    Have to tried man pdftex? This is Unix, you know. Dec 18, 2012 at 7:47
  • 1
    I tried XeLaTeX document and got kpathsea: Running mktexfmt XeLaTeX.fmt I can't find the format file XeLaTeX.fmt'!` and trying to use man XeLaTeX I got no manual entry for XeLaTeX so for people are starting to learn how to use TeX & friends without a GUI, answers to this would be very useful Sep 13, 2014 at 15:03
  • 4
    For a question considered by some to be 'not really good' it just received over 10 000 views, so it seems that a lot of people are interested in this at least.
    – McGafter
    Oct 27, 2015 at 9:29

4 Answers 4

19

You're right: latex filename.tex and the other above command are means to run a flavor of TeX from the command line.

They don't really require parameters, but you could also have a look at the configuration of GUI software like Texmaker, or type in the command line latex --help to show the complete list of available options. For example, the option -interaction=nonstopmode makes latex not stopping on every error...

These programs run in a single shot: they will not take action. For that, in Linux, you could write a Makefile that will arrange the required compilation steps, as shown here or here.

For the manual, you could try man latex, but I don't think that it is a good answer or question. The above commands run Latex/Pdflatex/... the same ways that a GUI editor will do.

2

In order for this to work, you need to make sure the TeX binaries are in your path, and that the version you want to run is in your path before any other binaries with the same names. If you install TeX from your OS package manager, it should set this up for you.

However, many distros package an old version of TeX Live, and you might need to install a newer one. In that case, you will need to set up your PATH for the binaries to work, as well as your MANPATH and INFOPATH for the command-line documentation.

To make the TeX live installer work properly, the commands you must add to your login scripts are similar to

PATH=/usr/local/texlive/2021/bin/x86_64-linux:$PATH
export PATH
INFOPATH=/usr/local/texlive/2021/texmf-dist/doc/info:$INFOPATH
export INFOPATH
MANPATH=/usr/local/texlive/2021/texmf-dist/doc/man:$MANPATH
export MANPATH

To enable them for all users, save them to a file, name it something like /etc/profile.d/texlive.sh, and chmod 755. To enable them only for your own user account, you would want to save them to ~/.bash_profile as well as ~/.bashrc, or to a single file that you source from both of these. (And if you changed your login shell, you don’t need these instructions.)

I personally set up one more command, a shell alias to update my TeX installation. I have TeX Live installed as the system user tex, which in theory means that an exploit in TeX Live at least should not get root.

alias update-tex='sudo -u tex -E $(which tlmgr) update --self --all'
1

First, make sure you install the latex package by executing the following command :

sudo apt install texlive-latex-base

Second, execute :

latex Filename.tex
1
  • 2
    And for all the beginners reading this: you probably have latexmk or arara installed, use one of them. Dec 13, 2019 at 23:46
1

Use makefile and have more freedom. An example would be:

# Generate your PDF
%.pdf : %.tex
        @echo '.........: pdflatex running pass 1...'
        pdflatex $< -o $@ 2>&1 | tee errors.err
        @echo '.........: bibtex running...'
        bibtex $(basename $<) 2>&1 | tee errors.err
        @echo '.........: pdflatex running pass 2...'
        pdflatex $< -o $@ 2>&1 | tee errors.err
        @echo '.........: pdflatex and bibtex run finished.'
# Clean temp files
clean :
        rm -f *.o errors.err
        rm -f *.aux *.bbl *.blg *.log *.out
        rm -f *.synctex.gz
        rm -f BUILD
        @echo

Command: $ make article.pdf

This will do:

  • pdflatex article.tex -o article.pdf : pass 1 to generate your PDF
  • bibtex article : this will update your bibliography
  • pdflatex article.tex -o article.pdf : after updating bibliography you need a pass 2 to update your PDF

Command: $ make clean

This command will remove all temporary files generated by the compilation process.

1
  • 2
    Note that pdflatex article.tex -o article.pdf doesn't do what you think it does! It typesets article.tex (which is by default saved to a PDF named article.pdf) then it adds the string -o article.pdf to be typeset at the end, but it does not appear there because the \end{document} stops processing before that. Dec 17, 2021 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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