Code highlighting in LaTeX (keywords: CTeX, WinEdt, minted, and highlight)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.