You are not logged in.

#1 2015-04-22 21:20:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Latex tips for vim users

-- Split from Vi(m)-like plugin for libreoffice? --

Per a request posted in the other thread, this was split off to serve as a place for sharing tips and tricks for effective use of LaTeX with vim.  As LaTeX is technically a programming language, and many of these tips may use vimscript, Programming & Scripting seems a good place for it.

My uses:
I use LaTeX for nearly everything - and I write my LaTeX documents in plain vim (vim-minimal).  I create documents, articles, handouts, and worksheets in LaTeX, I use the baposter class for conference posters, beamer for 'slideshow' presentations, and as I use R for all data analysis I use Sweave to integrate LaTeX and R.

Share:
How do you use LaTeX with vim?  What tips or tricks can you share?

Last edited by Trilby (2015-04-22 23:55:14)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#2 2015-04-22 22:51:23

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: Latex tips for vim users

Trilby wrote:

EDIT: I also learned how to properly use the forums wink

When I first read your triple post I thought it was recent and you were being sarcastic, but then I saw the actual date hehehe

Trilby wrote:

It's funny seeing my posts from 3 years ago.  I've been using latex for *everything* for at least a couple years now.

By the way, would you mind sharing how you use it? I mean, which editors and workflows do you usually use now? LaTeX is a huge ecosystem...

Last edited by thiagowfx (2015-04-23 04:29:40)

Offline

#3 2015-04-22 22:57:14

TheGuyWithTheFace
Member
Registered: 2012-12-09
Posts: 113

Re: Latex tips for vim users

thiagowfx wrote:

By the way, would you mind sharing how you use it? I mean, which editors and workflows do you usually use now? LaTeX is a huge ecosystem...

I'll second that while we're here. Off topic though it may be, I'm also interested in getting into LaTeX for types of papers not as easily handled by Libreoffice. I get the syntax (mostly) but any opinion on the general workflow and tools available would be very helpful. Whether here or a new thread (probably what we should do) I'd love to hear your thoughts Trilby.

Last edited by TheGuyWithTheFace (2015-04-22 22:57:29)

Offline

#4 2015-04-22 23:50:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: Latex tips for vim users

I'm pretty plain and simple: I just use vim with one added keybinding:

let g:tex_flavor = "tex"
nmap <F5> ;w<CR>;silent !latexmk -quiet -pv "%"; latexmk -c "%"<CR><CR>;redraw!<CR>

and ~/.latexmkrc

$latex = "pdflatex";
$cleanup_includes_cusdep_generated = 1;
$cleanup_includes_generated = 1;
$clean_ext = "bbl bib dvi nav snm spl 4ct 4tc idv lg tmp xref ttt fff";
$pdf_mode = 1;
$dvi_mode = 0;
$postscript_mode = 0;
$pdf_previewer = "mupdf %S";

Vim has good highlighting for latex (at least with tex_flavor set) and it even correctly highlights R code in the right places in Sweave documents.
For the latter, I have the following in ~/.vim/after/ftplugin/rnoweb.vim

nmap <F5> ;w<CR>;silent !Rscript -e 'Sweave("%")'; latexmk -quiet -pv "%:r"; latexmk -c "%:r"; rm "%:r".tex<CR><CR>;redraw!<CR>

Last edited by Trilby (2015-04-22 23:52:34)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2015-04-23 04:30:24

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: Latex tips for vim users

What about vim-latexsuite? It looks powerful (I know one or two friends who said once they use it), but I personally never tried it.

Last edited by thiagowfx (2015-04-23 04:30:34)

Offline

#6 2015-04-23 07:24:18

Psirus
Member
Registered: 2012-01-29
Posts: 45

Re: Latex tips for vim users

I'm not a big fan of the latexsuite, although I have to admit I didn't try it extensively, but based on my impression from tex.stackexchange.com, it seems to cause more problems than it solves. And as was already said, (La)TeX is just another "programming" language. I would like to mention a couple of plugins I often do use with LaTeX:

https://github.com/gi1242/vim-tex-syntax: Improved syntax file that works better with syntax-based folding and spellchecking.
https://github.com/garbas/vim-snipmate: Snippets; quickly insert templates for figures or tables, etc.; but not restricted to LaTeX
https://github.com/junegunn/vim-easy-align: Quickly align tables

Essentially, I'm using Vim instead of say Texmaker, because I want to keep my editing workflow (somewhat) independent from the language. The snippets and aligning plugins are just two examples that are very useful in LaTeX, but I'm using everywhere. Maybe there is a killer feature of latexsuite that I am missing; I hope someone can offer an insight.

Offline

#7 2015-04-23 10:37:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: Latex tips for vim users

Chainsaws are powerful.  Surgeons still use scalpels.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2015-04-23 14:42:03

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: Latex tips for vim users

I use the latexsuite for about ten years for amost everything, mostly for novel writing or poems. Never had a problem which couldn't be solved with minimal effort. It can take quite some time to configure if an unusual setup is needed, however, because this is really huge.

Alas, most german fiction publishers do not accept LaTeX so I have to convert the documents to Word readable formats afterwards, which is a real GRRR!


To know or not to know ...
... the questions remain forever.

Offline

#9 2015-04-23 14:48:11

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,793

Re: Latex tips for vim users

bernarcher wrote:

Alas, most german fiction publishers do not accept LaTeX so I have to convert the documents to Word readable formats afterwards, which is a real GRRR!

emacs has nice support for LaTeX as well.  I have a customer who insists that all deliverables be in Word format.  I develop my documents in LaTeX with multi-columns, tables, references, bibliographies, watermarks, etc...   When I am all done, I transfer the pdf to a Windows Box, fire up the Windows full version of Acrobat and export it as Word.  It is nice revenge -- the documents generally look pretty nice when loaded in Word, but they are absolutely impossible to edit in Word without completely destroying the formatting.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#10 2015-04-23 15:03:10

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: Latex tips for vim users

ewaller wrote:

... but they are absolutely impossible to edit in Word without completely destroying the formatting.

I've found that even to be true of documents originally created in word.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2015-04-23 23:29:35

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 653

Re: Latex tips for vim users

ewaller wrote:

the documents generally look pretty nice when loaded in Word, but they are absolutely impossible to edit in Word without completely destroying the formatting.

LOL, that's fantastic.

I personally use Asciidoc to produce all my documents, usually output to PDF. Asciidoc source text is easy to read and edit. It's the best doc solution I have found so far.

Offline

#12 2015-04-24 07:39:29

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Latex tips for vim users

Trilby wrote:
ewaller wrote:

... but they are absolutely impossible to edit in Word without completely destroying the formatting.

I've found that even to be true of documents originally created in word.

Which is why you shouldn't combine formatting and text creation in the first place...

I personally switched to a markdown/latex hybrid using pandoc. Writing is easy using markdown and the layout is done in latex (although I did go from markdown directly to pdf a couple of times now as I didn't need the complex stuff latex can do). Writing # instead of \chapter{} is just a lot easier...

Offline

#13 2015-05-04 02:54:54

owftheevil
Member
Registered: 2015-05-04
Posts: 1

Re: Latex tips for vim users

Trilby, thank for posting the code snippets above. I'm a new vim user (about 1 week now), so was having trouble getting a minimal tex setup working. Your code put me over the hump. 

I personnaly find it annoying to have to close and restart the viewer every time I recompile, so I cooked up this. As I said, I'm new to vim so please feel free to tell me if I'm doing anything stupid here.

let g:tex_flavor = "tex"
function! Compile_and_Preview()
	execute "write"
	execute "silent! !latexmk -quiet " . bufname("%")
	let pdf_name = "\"" . expand("%:r") . ".pdf\""
       	let mupdf_id = system("xdotool search --name " . pdf_name)
	if mupdf_id < 1
		execute "silent! !mupdf " . pdf_name . " &"
	else 
		execute "silent! !xdotool search --name " . pdf_name . " key r"
	endif
	redraw!
endfunction

nnoremap <F5> :call Compile_and_Preview()<cr>
inoremap <F5> <esc>:call Compile_and_Preview()<cr>

Offline

#14 2015-05-04 13:12:56

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Latex tips for vim users

runical wrote:

I personally switched to a markdown/latex hybrid using pandoc. Writing is easy using markdown and the layout is done in latex (although I did go from markdown directly to pdf a couple of times now as I didn't need the complex stuff latex can do). Writing # instead of \chapter{} is just a lot easier...

I do the same, although my instructors at university all expect *.docx files, so I output straight to *.odt and just use LibreOffice to indent paragraphs and save. Annoying, but still much less tedious than using a word processor. The vim-pandoc-syntax plugin is pretty nice too, though once a document gets around 1500 words in length Vim starts getting sluggish. Which is actually one of several reasons I've sold my soul and switched from Vim to the "One True Editor" for prose writing... tongue

Offline

#15 2015-05-07 16:58:26

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: Latex tips for vim users

Vim + DistractFree plugin + pandoc md

It would be an absolute godsend if there was a way for vim to scroll smoothly without jumping when wrap is set, ie that the entire line doesn't have to be in the window buffer.

Offline

#16 2015-05-07 17:24:47

parchd
Member
Registered: 2014-03-08
Posts: 421

Re: Latex tips for vim users

ANOKNUSA wrote:

I do the same, although my instructors at university all expect *.docx files, so I output straight to *.odt and just use LibreOffice to indent paragraphs and save.

You can create a reference odt file for pandoc that has the first line of each paragraph indented. Then you won't have to do that anymore.
Just take a pandoc-output odt file, edit the styles as desired, save as myreference.odt or something like that, then run pandoc with --reference-odt=/home/myself/myreference.odt

Offline

#17 2015-05-12 14:47:09

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Latex tips for vim users

parchd wrote:
ANOKNUSA wrote:

I do the same, although my instructors at university all expect *.docx files, so I output straight to *.odt and just use LibreOffice to indent paragraphs and save.

You can create a reference odt file for pandoc that has the first line of each paragraph indented. Then you won't have to do that anymore.
Just take a pandoc-output odt file, edit the styles as desired, save as myreference.odt or something like that, then run pandoc with --reference-odt=/home/myself/myreference.odt

Huh, I never knew that. I knew I could manually modify the styles, but didn't know something this simple was possible. Thanks.

Offline

#18 2015-05-20 21:31:23

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: Latex tips for vim users

Trilby wrote:

-- Split from Vi(m)-like plugin for libreoffice? --

Per a request posted in the other thread, this was split off to serve as a place for sharing tips and tricks for effective use of LaTeX with vim.  As LaTeX is technically a programming language, and many of these tips may use vimscript, Programming & Scripting seems a good place for it.

My uses:
I use LaTeX for nearly everything - and I write my LaTeX documents in plain vim (vim-minimal).  I create documents, articles, handouts, and worksheets in LaTeX, I use the baposter class for conference posters, beamer for 'slideshow' presentations, and as I use R for all data analysis I use Sweave to integrate LaTeX and R.

Share:
How do you use LaTeX with vim?  What tips or tricks can you share?

My combo includes:
* (pdf) latex with bibtex
* vim
* gnuplot
* asymptote/postscript
* GNU make.

The text is written in vim as a tex file. Schematic figures are done in asymptote or plain postscript (yes, I do have a 1992 book from Adobe).

Gnuplot deals with computed curves. One issue that I found with it is that it uses pretty bad fonts for captions, so I usually just produce plain plots, include them in a auxilllary tex file and add labels by hand using \put(){}. This is also how I make complicated figures with multiple panels.

All of the above is automated using make. So, from vim, I do ":!make doc" and the document  is ready. Since all the tools are scriptable, I can do e.g. "make figs" to produce pdfs of the figures, so my projects don't include any binary data, only scripts and text datafiles.


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#19 2015-05-22 21:28:14

flannelhead
Member
From: Finland
Registered: 2014-03-30
Posts: 55
Website

Re: Latex tips for vim users

Some really valuable tips here, thank you everyone!

What I've been wondering, though, is how do people who edit LaTeX in vim preview their documents? I tend to have a vim window and a PDF reader side-by-side in a tiling window manager and find it quite pleasant. However, I feel there might be even better workflows. I'd love to hear what everyone else uses.

Offline

#20 2015-05-22 22:22:00

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,793

Re: Latex tips for vim users

flannelhead wrote:

What I've been wondering, though, is how do people who edit LaTeX in vim preview their documents? I tend to have a vim window and a PDF reader side-by-side in a tiling window manager and find it quite pleasant. However, I feel there might be even better workflows. I'd love to hear what everyone else uses.

I actually use emacs, but the workflow is the same.  I compile to pdf's and open them with Okular.  The nice thing is Okular notices when the pdf changes at it updates automatically.  I also use make files to build my LaTeX documents and to keep bibliographies up to date.  I just run the make file from inside the editor environment.  As with other things emacs (and vim, I believe) the compiler out errors and warnings show up in a separate window (buffer in vim) that link to the source line in the tex file.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB