I've created LaTeX documents before using 'nice IDEs' such as TeXnicCenter and have a little experience in general with TeX, however, now I'm wondering about creating one "manually". By that, I mean doing something such as writing the tex document in a very simple editor (such as VIM) and then compiling it myself with pdflatex via the command prompt. Has anyone ever done this and if so, I really just need to know how I'd go about it? What's the process to doing it? While the IDE is nice, I'd really like to be able to create LaTeX documents 'on my own'. Thanks for any information you can provide!
4 Answers
Your question is a little confusing. What you mean is compiling a LaTeX document manually (into a PDF). You might want to adjust your title. Creating one would be the process of writing the document. This can be done in the command line using pdflatex <filename>
. In VIM you could just use ESC:!pdflatex %
(%
can be used instead of the current filename) when you edit the main file. There is also the LaTeX Suite for VIM which gives you short cuts for the compilation and a lot of IDE functionality.
The LaTeX compiler must be in your PATH
for this to work, but this should be already the case for a proper installed LaTeX.
The latexmk script (also called with the filename) will compile the LaTeX document as often as required and also run external tools like bibtex
and makeindex
, which is basically the things the IDE is doing automatically when you press the compile button.
-
13Oh come on, you don't have to tear his question to pieces like this. His last comment clarifies his post perfectly well. He has so far used a program that created the pdf with the press of a button, and now wants to know if there's anything he needs to know about producing (La)TeX output so by entering commands into some interface. There's really no reason to ridicule some minorly suboptimal wording in this manner. Apr 28, 2011 at 20:08
-
1See, your edit about
latexmk
is something someone coming from TeXnicCenter wouldn't know, for example. That's the kind of thing he was asking for. I think a GUI made him feel like he's "triggering a whole bunch of complex commands" (I'm exaggerating), and I'm sure he's right in the respect that there's certainly a lot to learn what can be done instead of "clicking that button", just likelatexmk
. Apr 28, 2011 at 20:34 -
10
Here is a basic tutorial for a Unix-like system (tested on Debian GNU/Linux). Yes, one can use latexmk
, arara
, shell scripts, or editor functions to automate much of this, but I wanted to demonstrate the simplest way to write and compile a LaTeX file "by hand" in the terminal.
- Open Terminal emulator
- Enter a directory where you will create your files. Type the command
cd /tmp
, or instead of/tmp
another directory you have permission to write to, like~/Documents/
. - Open the text editor in the terminal. Enter one of these commands:
nano hello.tex
(easiest to use for first time)vim hello.tex
emacs hello.tex
- Within the editor, type in the following code:
(file hello.tex
:)
\documentclass{article}
\begin{document}
\title{Hello and Goodbye}
\author{Your Name}
\date{\today}
\maketitle
\tableofcontents
\section{Hello}
Hello, world!
\section{Goodbye}
Goodbye, world!
\end{document}
- Save the file in the editor and quit the editor. Check for the file you created by listing the directory contents:
ls
. - Compile the document. Run
pdflatex
twice to get the table of contents. (Remember, in most terminals you can use the Up arrow on the keyboard to get the most recently entered command.)
pdflatex hello
pdflatex hello
- View the PDF you created. Use any PDF viewer:
mupdf hello.pdf
orevince hello.pdf
(on Mac,open hello.pdf
)
This procedure then continues: edit the file in the text editor, compile the file, preview the PDF.
You can make this system less cumbersome (depending on your perspective) by using a terminal multiplexer like tmux
or screen
, or just using multiple Terminal application windows. Then you can have one panel or window for editing the document in the text editor, and another panel or window for compiling it. If you have screen space, you can even keep a third window open with a PDF viewer; evince
on Debian and Preview
on Mac will update the PDF every time you recompile.
(PS - It's also a good idea to use git
or another version-control program. At the end of your session make sure you add the new file, or any changes to files, to your repository and then push to your offsite backup repository.)
-
2This answer is good because even if not short and to the point it gives the details of each step of the process. Also, instead of using the up arrow key to repeat previous command you can instead just write
!
in the terminal with same result. Also, you can press the tab key once you wrote the name of the file so it compiles the .tex file, and you point out the complete file name and not another one.– nilonJul 9, 2017 at 20:51
Create the file then compile it, just like you think you should. If your editor supports macros, define one (or two for Bibtex). However, I think it is better to stick with modern IDEs so you can take advantage of synchronized PDF previewing.
-
The orginal question is moving outside of IDE and clicking buttons. It specifically states how to compile "via the command prompt".– nilonJul 9, 2017 at 20:49
You can try AutomaticTexPlugin. It can compile documents on the fly or in the backround, so you do not waste the time, while waiting for the compilation. It also has a nice progress bar, which is serves well especially for big files. But the best point of this plugin is its excellent completion with lots of features (some people say that the only feature that is missing is that of writing the proofs by itself). Checkout the list of features (which is not even complete). The forward and backward search works out of the box for major linux and macos pdf viewers.
-
This seems a great option. Could you please give more detail on how it works: How to compile and what commands one should input in the command line or other wise?– nilonJul 9, 2017 at 20:55
-
pdflatex yourdocument.tex
, oryourtexengine yourdocument.tex
.