這篇文章將介紹如何在 Latex 排版過程中添加 Matlab 代碼
功能效果
主要有如下排版功能:
語法高亮
自動添加邊框
自動添加行號
先上圖,大家感受一下效果
listings 包
首先確保你能使用使用 listings 包
簡單快捷的使用方法如下
\usepackage{listings}
\lstset{language=Matlab}
\begin{lstlisting}
% Plot function f(x) = 2*x^3 - x - 2
ezplot('2*x^3-x-2',[0, 2])
hold on
plot([0,2],[0,0],'r')
\end{lstlisting}
1
2
3
4
5
6
7
8
9
我們來看一下效果:
接下來使用 mcode 風格
mcode 包
mcode下載地址
主要有三種使用方法
插入代碼塊
\usepackage{listings}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\begin{lstlisting}
% Plot function f(x) = 2*x^3 - x - 2
ezplot('2*x^3-x-2',[0, 2])
hold on
plot([0,2],[0,0],'r')
\end{lstlisting}
1
2
3
4
5
6
7
8
9
我們來看一下效果:
比較發現只是簡單的加入了如下一句代碼
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
1
段落中插入 Matlab 語句
只需在段落或頁腳編輯中插入如下語句
\mcode{for i=1:3, disp('cool'); end;}
\footnote{Works also in footnotes: \mcodefn{for i=1:3, disp('cool'); end;}}
1
2
即使用 \mcode{}
效果如下
嵌入 .m 文件
具體見下面的參考文獻,這里不多介紹
參考文獻
listings幫助文檔
mcode幫助文檔
————————————————
版權聲明:本文為CSDN博主「子辰曦」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/u012675539/java/article/details/47048163