Article directory
foreword
Creation start time: September 17, 2022 20:27:15
Here are the problems and solutions that occur when VSCode LaTeX uses the minted package. That is to say, it is a reasonable configuration scheme.
environment
- Windows 10
- Anaconda installed (with a Python 3.7 environment)
- VSCode
- MikTex has been installed, VSCode can already write LaTeX normally, but the minted package cannot be used
Problems encountered and solutions
The specific configuration scheme is problem-oriented and described as follows:
In the LaTeX project in VSCode add:
% preamble
\usepackage{minted}
% 文档区
\begin{figure}[htbp]
\centering
\inputminted[xleftmargin=0mm]{diff}{lists/xxx.list}
\caption{xxx}
\label{xxx}
\end{figure}
Then compile, it will report an error:
Package minted Error: You must invoke LaTeX with the -shell-escape flag.
At this time, according to the prompt:
1) Ctrl+shift+p
Call out settings.json
the file, find the following part and add a line of parameters:
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"--shell-escape", // 这个就是加上的参数
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
2) This is not enough, you also need to install Pygments
this python library, open the anaconda prompt, and then run:
conda install Pygments
ctrl+shift+p
3) Then call out in vscode : Python: Select Interpreter
, select your LaTeX project, and then select Pygments
the conda environment where you just installed the library.
Pygments
4) This is not enough, the executable file corresponding to the library (ie pygmentize.exe) must be added to the variable in the system environment variable PATH
. My path is:
D:\software\Anaconda\Scripts\pygmentize.exe
When I added it specifically, I added the directory:D:\software\Anaconda\Scripts
Then you can restart VSCode.
Then compile again, and it should be ready to use!
other knowledge
1) If an error is reported:
Package minted: Missing Pygments output; \inputminted wa s probably given a file that does not exist
or:
Package minted: Cannot find Pygments style xxx (such as perldoc, default and other styles).
The explanation is that pygmentize.exe is not added to the environment variable, and LaTeX cannot find this exe when compiling.
2) Minted has a lot of styles:
from pygments.styles import get_all_styles
styles = list(get_all_styles())
print(styles)
[‘default’, ‘emacs’, ‘friendly’, ‘friendly_grayscale’, ‘colorful’, ‘autumn’, ‘murphy’, ‘manni’, ‘material’, ‘monokai’, ‘perldoc’, ‘pastie’, ‘borland’, ‘trac’, ‘native’, ‘fruity’, ‘bw’, ‘vim’, ‘vs’, ‘tango’, ‘rrt’, ‘xcode’, ‘igor’, ‘paraiso-light’, ‘paraiso-dark’, ‘lovelace’, ‘algol’, ‘algol_nu’, ‘arduino’, ‘rainbow_dash’, ‘abap’, ‘solarized-dark’, ‘solarized-light’, ‘sas’, ‘stata’, ‘stata-light’, ‘stata-dark’, ‘inkpot’, ‘zenburn’, ‘gruvbox-dark’, ‘gruvbox-light’, ‘dracula’, ‘one-dark’, ‘lilypond’]
Specific style display:
- https://pygments.org/styles/
- How to create your own style: https://pygments.org/docs/styledevelopment/
summary
above. I saw that the results on Baidu are not complete, so I will write it here separately. Otherwise, there is no need to do repetitive work.
Creation end time: September 17, 2022 20:46:09
references
- Latex FAQ_qq_38420683's Blog - Programmer's Secret https://www.cxymm.net/article/qq_38420683/104347049
- Configuring VSCode to work with Minted (LaTeX) https://leportella.com/minted-vscode/
- Vscode configures latex code highlighting (minted) https://blog.csdn.net/u014454538/article/details/104283898
- Styles https://pygments.org/docs/styles/#getting-a-list-of-available-styles