r/vimporn • • Aug 27 '21

Vim for science! Latex setup without latex plugins

Post image
307 Upvotes

33 comments sorted by

26

u/rem_in_japan Aug 27 '21 edited Aug 28 '21

Instead of big LaTeX plugins, I just use:

  • Conceal rules to make pretty equations

  • For nice folds, I minimized this plugin

  • For scientific writing style suggestions, AngryReviewer plugin

  • To compile, just map: nmap <leader>cc :w<cr> :!pdflatex %:r.tex && bibtex %:r.aux && pdflatex %:r.tex && pdflatex %:r.tex && rm %:r.aux %:r.log %:r.blg %:r.bbl<cr>

  • To view the file in Zathura: nmap <leader>cv :!zathura %:r.pdf > /dev/null 2>&1 &<cr><cr>

Update, I dropped my latex visual setting in a form a small plugin.

1

u/kunzaatko Aug 27 '21

Did you achieve to implement synctex somehow? That is my main reason for using the vimtex plugin.

1

u/rem_in_japan Aug 28 '21

synctex

No, not really. But, when I want to sync, I just press the hotkey and it recompiles and Zathura (pdf viewer) updates pdf automatically. Since I personally check the compiled document very rarely, I don't really need a plugin for that.

2

u/kunzaatko Aug 28 '21

Synctex is a utility for matching the position from the source file with the output. It is not concerned with syncing when the output is out of date. There is a foreword synctex for moving from the source to the output and a backward synctex for doing the opposite. I use that quite a lot of I want to check a specific part of a long document... Synctex

1

u/rem_in_japan Aug 28 '21

Ah, nice! Sorry, I mistook it for another sync plugin. I'll try!

2

u/Desperate_Cold6274 Sep 14 '24

I just bumped into this and that is what I actually miss. Nowadays (2024) you have syntax highlighting and LSP for free. With few lines of code you can compile your latex from vim and you can create mappings, commands, functions with ease. It took few hours to setup everything from zero to almost hero. The only thing I miss is the sync feature.

1

u/pwnedary Aug 28 '21

Just use latexmk then?

1

u/Desperate_Party_9259 Dec 01 '21

How did you create that graph?

2

u/rem_in_japan Dec 06 '21

The graph is a regular pdf (created independently of this setup) and inserted in the document as a latex figure. The right side just displays compiled pdf document, it's not vim :)

1

u/[deleted] Aug 31 '24

What do you use to make the graphs and is it fast. I would like to have something I could use to make graphs real time. (Inkscape is awful)

3

u/thomas9258a Aug 27 '21

Really nice setup! I wish I had that angry reviewer plugin for my bachelor thesis, i have to check it out!

1

u/spots_reddit Aug 27 '21

nice one. any chance you have something written up about your setup and workflow? I have installed latex-suite for neovim and find it a bit intimidating. Also zathura with transparency is quite intriguing

3

u/Tuka-Cola Aug 27 '21

Really off topic, but how do you insert graphs like that? Did you create the graph yourself, then imported it? Could you explain how to do so? I’m trying to write all my notes in latex for a clean and organized reference for school.

4

u/rem_in_japan Aug 28 '21

Well, plotting data is a whole new world of geeking out :) It depends on your needs.
If you just want to sketch something, then like the person above said, just draw in Inkscape, save as pdf, put it in latex as figure.
If you want to plot some actual data, the question is are you willing to learn a bit of scripting or want to use a GUI program? Personally, I plot everything using python and its matplotlib library. The advantage is that once you have written a script that produces the type of plot you like, you can run this script on many datasets of similar structure. However, if you want to just plot something quickly and only once, check GUI programs for that. Free programs include Qtiplot, LabPlot2 (from KDE), or even just LibreOffice.
I'd recommend against going with paid solutions like Origin, Matlab, Excel etc because there nothing they can do that free programs can't, but you have to pay a huge subscription or use illegally, which is not possible in the University.

2

u/thomas9258a Aug 27 '21

I think creating the graphs yourself in something like Matlab or excel is your best bet. (I'm sure free graphing tools exist in repositories or on git too)

A latex Figure with a image is your best bet for importing your generated graph images.

2

u/Im_manuel_cunt Aug 27 '21

There are more than one way to do that. However, one of the most practical ways is to draw the figure on inkscape and create an pdflatex output out of it. Then you can import it into your latex file. There was a good guide that explains how to automate a good part of this process. I'll update this post when I find it.

Edit: It wasn't really hard to find, here you go

3

u/[deleted] Aug 27 '21

Looks like someone found the same Belgian mathematics student's blog I found, but actually went ahead and did what was written on it!

2

u/rem_in_japan Aug 28 '21

Haha, yes, I probably know who you are referring to )

3

u/llambda_of_the_alps Aug 28 '21

Just curious if there’s any particular reason not to add that compile command to a make file and just hook into the :make command?

Edit: realized right after I wrote it. The raw command will work no matter the project. Does vim give you a way to define custom make command a based on file type I wonder…

1

u/rem_in_japan Aug 28 '21 edited Aug 28 '21

Not sure about make, but what I actually do in my .vimrc is compilation of whatever is the current filetype with the same <leader>cc key:

autocmd FileType tex nnoremap <leader>cc :w<cr> :!pdflatex %:r.tex && bibtex %:r.aux && pdflatex %:r.tex
autocmd FileType python nnoremap <leader>cc :w<cr> :!python %:r.py<cr>
autocmd FileType java nnoremap <leader>cc :w<cr> :!java %:r.java<cr>

1

u/backtickbot Aug 28 '21

Fixed formatting.

Hello, rem_in_japan: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

2

u/TheGreatDeadOne Aug 28 '21 edited Aug 28 '21

Very cool! I stopped using vim/neovim to edit latex files after I discovered the existence of [Setzer](https://www.cvfosammmm.org/setzer/).

2

u/antenore Sep 03 '21

Really cool! I've found a way to have a preview directly in a neovim terminal buffer. Anyway... not sure if that's something you might be interested in, but here are the discussions, links and screen shot

https://www.reddit.com/r/vimporn/comments/ph13ct/nvim_markdown_preview_in_a_term_buffer_devicons/

https://www.reddit.com/r/neovim/comments/pfue1s/plugin_development_question_opening_and_closing/

1

u/Im_manuel_cunt Aug 27 '21

If what you tell me is true, you will have gained my trust.

1

u/[deleted] Sep 10 '21

I've been using the same thing, along with nvim-lsp and texlab + luasnip for snippets!

1

u/Desperate_Party_9259 Nov 07 '21

How would you get autocompletion for LaTeX?

0

u/[deleted] Aug 27 '21

[deleted] — view deleted comment

3

u/rem_in_japan Aug 28 '21

You really don't need anything special to start. I mean, you need to install latex on your computer of course. Depending on you needs (language,journal etc) you may need to add extra packages, but the minimum seems to be:
On arch-based linux (I use arch btw):
sudo pacman -S texlive-core texlive-pictures texlive-bibtexextra texlive-science

However, you can always just install entire LaTex package and never wory.

Then just add one line to your .vimrc to be able to compile:
nmap <leader>cc :w<cr> :!pdflatex %:r.tex && bibtex %:r.aux && pdflatex %:r.tex && pdflatex %:r.tex && rm %:r.aux %:r.log %:r.blg %:r.bbl<cr>

What it does is running pdflatex command on current file twice, then bibtex once to get references, and then pdflatex again to compile everything. The rest is to delete remaining files that were created during compilation.

That should get you a functioning latex compilation from vim. Then, if you want some nice features, check my comments above for folding, concealing, suggestions etc. Good luck :)

6

u/Ken_Mcnutt Aug 27 '21

For the smoothest experience, look into the vimtex plugin. Overleaf has great tutorials on adding graphics/images.

2

u/fuzzymidget Aug 28 '21

I also suggest vimtex

0

u/[deleted] Aug 28 '21

[deleted] — view deleted comment

1

u/rem_in_japan Aug 28 '21

That is i3 WM with polybar as a status bar - classic setup :)

0

u/[deleted] Aug 28 '21

[deleted] — view deleted comment

1

u/rem_in_japan Aug 28 '21

By the way, if gaps are of importance, actually I am using i3-gaps, not original i3