# trouble with packages dsfont and minted with using vimtex

I'm trying to use vim / nvim as text editor in a (long) .tex file containing both minted and dsfont package. Here is an example:

% !TeX document-id = {f2e9e8a7-1386-4a73-9989-55350ce6c529}
% !TeX TXS-program:compile = txs:///xelatex/[--shell-escape]
%\documentclass[a4paper, 12pt]{book}
\documentclass{scrreprt}
%\usepackage{fontspec}
%\usepackage{pmboxdraw}
\usepackage{amssymb, amsmath, float, framed, geometry, listings, lmodern, mathtools,multirow,parskip, paralist,pgfplots, ragged2e,setspace,tcolorbox, threeparttable, upquote, url, tikz, enumitem}
\usepackage{bbm}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{xurl}
\usepackage{minted}
\usepackage{dsfont}
\usepackage{multirow}
\usepackage{tabto}
\usepackage{tabu}
\usepackage[english]{babel}
\usepackage{newtxmath}
\usetikzlibrary{positioning}
\usepackage{xcolor}
\definecolor{mypink1}{RGB}{0, 170, 0}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\rfoot{Page \thepage}
\usepackage[LGR]{fontenc}
\usepackage[T1]{fontenc}
\hypersetup{
filecolor=magenta,
citecolor=mypink1,
urlcolor=cyan,
}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
\usepackage{caption}
%\usepackage{calrsfs}
%\DeclareMathAlphabet{\pazocal}{OMS}{zplm}{m}{n}
\begin{document}
blabla
\begin{minted}{Python}
print(“Hello world”)
\end{minted}
\end{document}



I can compile the document with both Texstudio and pdflatex in the terminal without problems. However trying to view it with :LLPStartPreview gives me a Failed to compile message and a the following message in the .log file:

l.13 \usepackage
{dsfont}
Pass the -shell-escape flag to LaTeX. Refer to the minted.sty documentation for



I had a look at the minted doc but couldn't find the solution to the problem What am I doing wrong?

Edit1

After having checked this other answer, I also tried to replace the line

% !TeX TXS-program:compile = txs:///xelatex/[--shell-escape]


by

% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]


and

% !TeX TXS-program:pdflatex = pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex


but it didn't solve the problem

Edit 2 I try to insert (in .vimrc file)

let g:vimtex_compiler_latexmk.options += ['-shell-escape']
let g:vimtex_compiler_method = 'latexmk'


and

let g:vimtex_compiler_latexmk.options += ['-shell-escape']
let g:vimtex_compiler_method = 'latexmk'


but it didn't solve the problem

Edit 3 I tried (sequentially) to add the following command in the .vimrc file but it didn't solve the problem:

• let g:livepreview_engine = 'evince' . [-shell-escape]
• let g:livepreview_engine = 'evince' . ['-shell-escape']
• let g:livepreview_engine = 'evince' . '[-shell-escape]'
• let g:livepreview_engine =. ' -shell-escape'

Edit 4 I tried also to add the following line in my .vimrc without success let g:livepreview_engine = 'pdflatex' . '[-shell-escape]'

The problem didn't appear when I used :LLPStartPreview with the following code: (where the following lines where commented out):


...
\usepackage{minted}
...
\begin{minted}{Python}
print(“Hello world”)
\end{minted}

% !TeX document-id = {f2e9e8a7-1386-4a73-9989-55350ce6c529}
% !TeX TXS-program:pdflatex = pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex
%\documentclass[a4paper, 12pt]{book}
\documentclass{scrreprt}
%\usepackage{fontspec}
%\usepackage{pmboxdraw}
\usepackage{amssymb, amsmath, float, framed, geometry, listings, lmodern, mathtools,multirow,parskip, paralist,pgfplots, ragged2e,setspace,tcolorbox, threeparttable, upquote, url, tikz, enumitem}
\usepackage{bbm}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{xurl}
%\usepackage{minted}
\usepackage{dsfont}
\usepackage{multirow}
\usepackage{tabto}
\usepackage{tabu}
\usepackage[english]{babel}
\usepackage{newtxmath}
\usetikzlibrary{positioning}
\usepackage{xcolor}
\definecolor{mypink1}{RGB}{0, 170, 0}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\rfoot{Page \thepage}
\usepackage[LGR]{fontenc}
\usepackage[T1]{fontenc}
\hypersetup{
filecolor=magenta,
citecolor=mypink1,
urlcolor=cyan,
}
\geometry{
a4paper,
total={170mm,257mm},
left=20mm,
top=20mm,
}
\usepackage{caption}
%\usepackage{calrsfs}
%\DeclareMathAlphabet{\pazocal}{OMS}{zplm}{m}{n}
\begin{document}
blabla
%\begin{minted}{Python}
%   print(“Hello world”)
%\end{minted}
\end{document}

• dsfont has nothing to do with this. You need to enable shell-escape for processing documents relying on minted. See tex.stackexchange.com/q/99475/4427 – egreg Feb 2 at 16:26
• Thank you for your comment @egreg. I checked the linked and tried to modify the .tex file accordingly but it didn't solve the problem (when trying to use specificall :LLPStartPreview although it works in texstudio). I edited the question accordingly – ecjb Feb 2 at 16:33
• let g:livepreview_engine = 'evince' . [-shell-escape] requires the pdfengine, ie. something like latexmk or pdflatex, not evince. Evince is a pdfviewer – DG' Feb 3 at 9:05

EDIT: After DG' pointed out a major misconception I had it looks like what has to be altered is not the compilation route of vimtex but the route of vim-latex-live-preview. According to its README, the compilation can be controlled by setting g:livepreview_engine. To add the -shell-escape option to it one could do

:let g:livepreview_engine .= ' -shell-escape'


Unfortunately I don't use vim-latex-live-preview so can't test this.

Note: I don't use vimtex personally, so I can't verify whether the following really works. But I include the way one could find the information necessary for all this and think that it should work (it's what I'd try).

vimtex is not TeXstudio and doesn't parse for TeXstudio's magic comments, afaik.

If in vim (or nvim for what it's worth) you can get help on most things by typing :help <thing> and hitting enter. In particular you can get help about vimtex by typing :help vimtex. There you'll find information on the used compilation method and how to customize it. (For others who don't have vimtex installed, the help file can be found here)

By default vimtex uses latexmk. You should/could change the options passed to latexmk by changing the g:vimtex_compiler_latexmk dictionary, more specifically change the options field of that dictionary. For that you can type the following in normal mode:

:let g:vimtex_compiler_latexmk.options += ['-shell-escape']


Hit enter. Now for the current vim session you'll compile with -shell-escape allowed and minted should work out.

Alternatively you could also configure vimtex to use another compile route. vimtex supports:

• latexmk
• latexrun
• tectonic
• arara

You can choose among these by setting g:vimtex_compiler_method like so (example uses arara):

:let g:vimtex_compiler_method = 'arara'


The example above uses arara because you can configure arara by using magic comments, but I'm no expert for arara either, so either search for information about it or consult its pretty documentation.

• many thanks for your answer @Skillmonlikestopanswers.xyz. I tried to modify the .vimrc file accordingly (see Edit 2 in my question) but it didn't solve the problem – ecjb Feb 2 at 23:46
• @ecjb have you resourced your rc? Also did you insert that after vimtex gets loaded? As an aside, I don't recommend generally allowing -shell-escape in your .vimrc for every LaTeX project and would only allow that per session with the code above! Did you try using that with an already started vim, like suggested in my answer? As I said, I can't test this at all, so I'm a bit in the dark here and can only guess. – Skillmon likes topanswers.xyz Feb 2 at 23:54
• FWIW: The OP claims to be unsing vimtex but the command LLPStartPreview is provided by vim-latex-live-preview, which is configured with: let g:livepreview_engine = 'your_engine' . ' [options]'  – DG' Feb 3 at 0:03
• @Skillmonlikestopanswers.xyz: So I removed the let g:vimtex_compiler_latexmk.options += ['-shell-escape'] as you advised and tried to enter it during the session. That unfortunately didn't help. By "resource my rc", do you mean restart the terminal (I'm on MacOS) ==> If yes, I restarted the terminal after editing the .vimrc but it didn't solve the probelm. Finally "after vimtex gets loaded: you mean after loading a .tex file with vim? ==> if yes, that didn't solve the problem. But many thanks for your comments! – ecjb Feb 3 at 0:05
• Maybe also relevant: github.com/lervag/vimtex/issues/305 – DG' Feb 3 at 0:06