Latex is a text-typesetting language that can be formatted with all the effects we want. And the advantage of code layout is easy to modify the plate, so in the text content of the composition, latex application is very extensive.
When we need to insert code in Latex, we need to use the \USEPACKAGE{LISTINGS} macro package. For example, insert a simple C language code
#include <stdio.h>int main (intChar * * argv) {printf (" Hello, world!\n"); return 0 ;}
To put the above hello,world! This c language code uses latex to achieve the effect of typesetting, latex script is as follows
\documentclass{article}\usepackage{Listings}\usepackage{Xcolor}% code Coloring Macro Pack \usepackage{CJK}% display Chinese macro Pack \lstset{Basicstyle=\tt,% line number Numbers=left, rulesepcolor=\color{red!20!green!20!blue!20}, Escapeinside=", Xleftmargin=2em,xrightmargin=2em, aboveskip=1em,% background frame framexleftmargin=1. 5mm, Frame=shadowbox,% background color backgroundcolor=\COLOR[RGB]{245,245,244},% style Keywordstyle=\color{Blue}\bfseries, Identifierstyle=\BF, NumberStyle=\COLOR[RGB]{0,192,192}, Commentstyle=\IT\COLOR[RGB]{96,96,96}, Stringstyle=\RMFAMILY\SLSHAPE\COLOR[RGB]{128,0,0},% display space showstringspaces=false}\begin{Document}\begin{cjk*}{GBK}{Song}\lstset{Language=c}\begin{lstlisting}% Insert the code to display # include<stdio.h>int main (int argc, char**argv){/* ' print ' hello,world*/printf ("Hello, world!\n"); return 0;}\End{lstlisting}\End{cjk*}\End{Document}
The latex script above can show comments in the C language (including Chinese comments), code coloring, and add code line numbers. The effect is as follows
Inserting C language code into latex