Today, I want to insert code in LaTeX and highlight it. I suggest using the listings macro package on the Internet. However, I tried it and found that the effect was average.
Later I found another macro package named minted, which is easy to use and has good results. The effect of c ++ is as follows:
However, there are a lot of things to install. The following describes the installation process.
My environment is win7-64bit, has been installed with the CTeX package, usually use WinEdt to edit (that is, how to add command line parameters on WinEdt plagued me for half a day ).
1. If the CTeX package has been installed, the minted macro package is available and does not need to be downloaded.
Minted details in: http://ctan.org/pkg/minted
You can download the document to see it.
2 installation requiredPython,: Http://python.org/download/releases/2.7.5/
Because the installation documentation is about python2, you have not downloaded python3. For incompatibility reasons, assume that the installation path is"C: \ Python27", Add this path to the system variablePath.
3 installationEasy_installThis is a silly installation package. With this package, you can simply install the following package.
: Https://pypi.python.org/pypi/setuptools/0.7.4#windows
Download this file: ez_setup.py
Run the following command on the command line:Python ez_setup.py
In this way, the easy_install tool is installed. You can see that there is an additional Scripts folder in C: \ Python27,C: \ Python27 \ Scripts"Added to the system variablePath.
4 installationPygments(For more information, see http://pygments.org/download)
Run the following command directly on the command line:Easy_install Pygments
This will automatically help you download and install, so it is silly, and the final installation result is in"C: \ Python27 \ Scripts.
5. Write the LaTeX Code directly in WinEdt as follows:
\documentclass[CJK]{cctart}\usepackage{minted}\begin{document}\begin{minted}{c++}int main() { printf("hello, world"); return 0;}\end{minted}\end{document}
It cannot be compiled because it is missing-Shell-escapeParameters
How can I add a great deal of effort, and finally found that in WinEdt, Options, Execution Modes, Console Applications, there is a column on the left of various commands, these commands can be selected, then modify the parameter in the following parameters. I currently use parameter texify, so Add"-- Tex-option =-shell-escape"That's all,
In this way, you can compile the program. (I have been adding it after the latex command, but it does not work ).
6. The final problem is that the file is compiled successfully, but the displayed pdf is blank. This may be because the language in \ begin {minted} {language} is wrong when minted is used, for example, if I write lowercase c as uppercase C, the Code cannot be displayed.