插入matlab代码 【latex|latex插入代码块】在开始加入
\usepackage{listings}%插入代码块
在需要添加代码的地方
\begin{lstlisting}[language = Matlab,title={matlab4\_8.m},numbers=left,
numberstyle=\tiny,keywordstyle=\color{blue!70},
commentstyle=\color{red!50!green!50!blue!50},frame=shadowbox,
rulesepcolor=\color{red!20!green!20!blue!20},basicstyle=\ttfamily]\end{lstlisting}
在end之前添加代码,可编译得到不错的高亮效果

文章图片

文章图片
matlab官方latex包 下载matlab官方包mcode
在文件开始位置添加
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}%matlab代码块
在代码前后添加
\begin{lstlisting}\end{lstlisting}

文章图片
插入python代码 下载第三方宏包pythonhighlight并放在tex文件同一文件夹
在文档开始添加
\usepackage{pythonhighlight}%插入python代码
在代码前后添加
\begin{python}\end{python}
添加代码并编译,可得到不错的效果

文章图片

文章图片
推荐阅读
- Latex教程目录
- Latex智能图
- Latex表格
- 什么是Latex()
- Latex TEXMAKER概述
- Latex简历和模板
- Latex符号
- Latex偏导
- Latex Overleaf使用详解