>{\物链scshape} 改变其后列的字体设置
>{\$} 其后列数据前插入美元符号
<{T} 其前面列数据后插入字母T
>{$}r<历塌{$}该列数据前后插罩烂孙入数学模式标记,该列内容为数学模式
!{\abc} 将声明\abc插入到两列之间
首先下载演示文件
style文件下载地址:
http://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package
http://www.mathworks.com/matlabcentral/fx_files/8015/10/mcode.zip
演示文件下载:http://www.knorn.org/misc_files/mcode_demo.zip
使用方法:
1. 在Latex开头加载package
% load package with ``framed'' and ``numbered'' option.
\usepackage[framed,numbered]{mcode}
2.需要加入Matlab代码的地方使用
2.1如果在同一行显示 使用\mcode{Matlab代码}
例如 \mcode{for i=1:3, disp('cool')end}
2.2 如果需要在矩形框里显示,并加入行号,使用lstlisting
如:
\begin{lstlisting}
for i=1:3
disp('cool') 笑碰差 % comment with some &#194§\mcommentfont\LaTeX in it: $\mcommentfont\pi x^2$&#194§
x_last = x(iend)
end
\end{lstlisting}
2.3也可以直接给碰皮出Matlab文件名,
lstinputlisting{/SOME/PATH/FILENAME.M}
或者自己定义开始,结束吵胡的行号
lstinputlisting[firstline=6, lastline=15]{/SOME/PATH/FILENAME.M}
最终显示如下:
让空格可以断行同时不被吃掉,可以重定义 \@xobeysp 为 \hspace{0pt}\mbox{ }\hspace{0pt}允许连字符,可以重设 \hyphenchar
在 \verb 开始处增加 \hspace*{0pt} 设置一个虚拟词,以允许第一个词后断开。
不过呢,这个要求比较怪。主要是连字符。需要使用特殊字符的代码中所有字符都可能是有特别意义的,通常颤悉都不能接受混入多余的连字符,以免与减号之类的混淆。
而如果只是允许空格断行好好的话,不需要上面的方式,很多宏包就可以完成了。例如 listings 可以全局或局部设置 breaklines 选项,如果你仔细读文档了的话。
\documentclass{article}
\usepackage{etoolbox}
\makeatletter
\def\@xobeysp{\hspace{0pt}\mbox{ }\hspace{0pt}}
\appto\verbatim@font{\hyphenchar\font`-\relax}
\apptocmd\@sverb{\hspace*{0pt}}{}{}
\makeatother
\usepackage{listings}
\lstset{basicstyle={\normalfont\sffamily},breaklines}
\begin{document}
\parindent=0pt
\hsize=4em
\verb|#Hyphenation# and %allowlinebreak%|
\lstinline|this is also breakable|
\end{document}
\documentclass{article}
\usepackage{etoolbox}
\makeatletter
\def\@xobeysp{\hspace{0pt}\mbox{ }\hspace{0pt}}
\appto\verbatim@font{\hyphenchar\font`-\relax}
\apptocmd\@sverb{\hspace*{0pt}}{}{}
\makeatother
\usepackage{listings}
\lstset{basicstyle={\normalfont\sffamily},breaklines}
\begin{document}
\parindent=0pt
\hsize=4em
\verb|#Hyphenation# and %allowlinebreak%|
\lstinline|this is also breakable|
\end{document}
verb-linebreak
注意 listings 的断行规则可能严一些,空格也是可伸缩的。
此外,如果是 url、文件路径之友洞铅类东西,用 url 宏包的 \url 更好。它的实现原理与 \verb 之类命令不大一样,断行规则也不同。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)