## Vim + LaTeX and YOU!

Author’s note: I think I can make this one short.

Notice how we’re still in insert mode and that this file hasn’t been saved yet. For some, this is all they want, the ability to have a live preview rendering of their drawing. To receive that WYSIWYG culture intersected with the WYSIWYM dogma which is life. That’s what  the kids want these days. I didn’t write this, it’s simply yet another plug-in for vim. What I will go over, is how this tool in combination with a few little hacks helps to streamline report making.

Okay, the secret sauce is in the makefile.

TARGET=filename
PDFVIEWER=evince

all: $(TARGET).pdf ## Generalized rule: how to build a .pdf from each .tex LATEXPDFS=$(patsubst %.tex,%.pdf,$(wildcard *.tex))$(LATEXPDFS): %.pdf: %.tex
pdflatex -interaction nonstopmode $(patsubst %.pdf,%.tex,$@)

# removes intermediate files
clean:
rm *.aux *.log || true

# removes intermediate files AND the .pdf you made
veryclean: clean
rm $(TARGET).pdf # compiles file and uses evince to view document, or use your favorite viewer! view:$(TARGET).pdf
$(PDFVIEWER)$(TARGET).pdf

# in case you're working in a sub-folder and need to send elsewhere
submit: $(TARGET).pdf cp$(TARGET).pdf ../

# lpr will use default printer and default printer settings
print: $(TARGET).pdf lpr$(TARGET).pdf

.PHONY: all clean veryclean view print

For yourself, the “filename” variable should be changed to your filename without the extension. So if your filename is “myFinalReport002.tex” the first line should read “TARGET=myFinalReport002”. PDFVIEWER should be set to whichever pdfviewer you prefer on your machine. Evince is the one used here.

mkdir a  folder for your latex report. In this folder, you’ll want both this makefile and the myFinalReport002.tex that you’re working on. The sample *.tex file in the screen shot above is simply this

% This is a sample input file
% & $# % _ { } ^ ~ \ are all special characters \documentclass{article} \begin{document} \section{Simple Text} Words are separated by one or more spaces. Paragraphs are separated by one or more blank lines. The output is not affected by adding extra spaces or extra blank lines to the input file. Double quotes are typed like this: quoted text''. Single quotes are typed like this: single-quoted text'. Long dashes are typed as three dash characters---like this. Emphasized text is typed like this: \emph{this is emphasized}. Bold text is typed like this: \textbf{this is bold} \subsection{A warning or Two} If you get more space after a mid-sentence period---abbreviations like etc.\ are common culprits---then type a backslash followed by a space after the period, as in this sentence. Remember, don't type the 10 special characters (such as dollar sign and backslash) except as directed! The following seven are printed by typing a backslash in front of them: \$ \& \# \% \_ \{ \}.
The manual tells how to make other symbols.

Greetings people who read my blog! o/

\end{document}

With these two files in your working directory you can simply call make, make clean, make veryclean, make submit, make view, and finally makelpr (for when you want to print and are on the go). A person can pretty much put whatever commands they want to inside the makefile, but here’s something neat about using vim with the makefile.

:make view

Just as you normally would :w or :wq,  vim has an inbuilt function where it runs commands inside of a makefile that’s in the same directory. There’s no need to open up a 2nd terminal screen or to exit vim to check you work (or submit the report). If typing in :make view is too much for you, you can always remap the commands in your .vimrc like so

155 " LaTeX fun - in lou of :make view
156 command MV w | make view
157
158 " LivePreview
159 let LLPSTartPreview = "VLP"

If typing :mv becomes too much for you, and constantly checking and rechecking your work puts a strain on your body, mind, and soul; then there’s a way to make this viewing thing a bit more automated. Aforementioned, there’s a plugin.

cd into your ~/.vim/bundle and simply

git clone https://github.com/xuhdev/vim-latex-live-preview`

To begin, all you need to do is invoke :LLPSTartPreview in your vim terminal, but adjust that .vimrc for a more pleasant experience. The READ.md instructions for this plugin does not explicitly mention pathogen(), but /bundle is the defacto /plugin folder. These quick instructions should get most people started, but for this plugin to work you’ll need to make sure that your vim has been compiled with a specific configuration, e.g. python. Most vim installs on a new system are meant to be light weight, and quick to load. If you’re having issues while compiling your own heavy duty vim installation you might find this post helpful.