latex显示源代码
使用\verb或者verbatim环境 显示latex的源代码, 也可以用listings宏包.
一个例子
\documentclass[11pt]{article}
\usepackage{verbatim}
\usepackage{comment}
\begin{document}
This document demonstrates the \verb=verbatim= environment
and \verb=\verbatiminput= command. It also demonstrates the
\verb=comment= environment, but you have to look at the TeX
source to see that (of course).
Here is a short piece of Maple code to demonstrate the
the \verb=verbatim= environment:
\begin{verbatim}
> eqn:=diff(y(t),t,t)+4*y(t)=0:
> inits:=y(0)=1,D(y)(0)=-1:
> dsolve({eqn,inits},y(t));
\end{verbatim}
$$
\mathrm{y}(t)= - \frac{1}{2}\,\sin(2\,t) + \cos(2\,t)
$$
\begin{comment}
Put a few paragraphs you have not decided about yet here for future
work. They will not appear in the output. You can also put comments
or reminders here. For example, you may want to remind yourself that
Maple has a nice LaTeX export feature which may be more convenient
than the by-hand approach used above.
\end{comment}
To demonstrate the \verb=\verbatiminput= command this file will
input itself, which is pretty cool. To make sure
this file can find itself to input, we use the \verb=\jobname=
command in the argument to \verb=\verbatiminput=. Thus everything
will work even if you rename this file.
\end{document}
-------------------------------------------------------
使verbatim环境在XeTeX下支持中文
研究了一下verbatim.sty,发现verbatim环境默认使用ttfamily的字体,因此只要重定义
\verbatim@font宏使verbatim默认使用rmfamily或sffamily字体,通过\setromanfont或
\setsansfont设置相应字体族为中文字体即可。
\documentclass[a4paper]{article}
\usepackage{fontspec,xunicode,xltxtra,verbatim}
\setsansfont[BoldFont={"[simhei.ttf]"}]{"[simsun.ttc]"}
\setromanfon[BoldFont={"[simhei.ttf]"}]{"[simsun.ttc]"}
%设置字体时也可以直接用字体名,以下三种方式等同:
%\setromanfont[BoldFont={黑体}]{宋体}
%\setromanfont[BoldFont={SimHei}]{SimSun}
%\setromanfont[BoldFont={"[simhei.ttf]"}]{"[simsun.ttc]"}
%但是不推荐使用第一种方式,对于中文名称的字体,使用该方式会导致不能将
%roman、sans族字体设置为同一种字体,比如将romanfont和sanfont都设置为"宋体"
%将导致编译错误。但是用另外两种方式却没问题,也许是fontspec包的bug吧。推
%荐直接指定字体文件名的第三种方式。
\begin{document}
Can you see some CJK characters in the verbatim?
\makeatletter
\def\verbatim@font{\sffamily\small} %如果使用roman字体族,将sffamily改成rmfamily
\makeatother
\begin{verbatim}
some ascii characters!
你能看到中文字符嘛!
\end{verbatim}
\end{document}
ps: 此文最初发表于水木清华TeX版
from: http://www.365bloglink.com/go.php?id=soGuWt3ui
--------------------------------------
用LaTeX写论文时,插入C++源代码有专门的宏包,方法如下:
\usepackage{listings}
\lstset{language=C++}%这条命令可以让LaTeX排版时将C++键字突出显示
\lstset{breaklines}%这条命令可以让LaTeX自动将长的代码行换行排版
\lstset{extendedchars=false}%这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题
\begin{lstlisting}
%paste your C++ code here
\end{lstlisting}
from: http://yichangren.blog.hexun.com/9057534_d.html
没有评论:
发表评论