Latex中输入python代码——定制Latex代码风格

github开源代码:
https://github.com/cc1416619381/python-latex-highlighting

使用方法:

  1. 到github上download源文件,解压,将 pythonhighlight.sty 文件复制到你的工程目录下(即 .tex 文件所在目录);
  2. 通过 \usepackage{pythonhighlight} 引用宏包,通过 \begin{python}\end{python} 包裹python代码,如下:
\documentclass[a4paper]{
   article}
\usepackage[margin=1in]{
   geometry
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LaTeX 输入 SPSS 代码和 MATLAB 代码的方法如下: 1. SPSS 代码 使用 `listings` 宏包可以在 LaTeX 输入 SPSS 代码。以下是一个例子: ```latex \usepackage{listings} \lstset{ language=SPSS, basicstyle=\ttfamily, keywordstyle=\bfseries, commentstyle=\itshape, stringstyle=\ttfamily, showstringspaces=false, breaklines=true, numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt, backgroundcolor=\color{gray!10}, frame=single, rulecolor=\color{black!30}, captionpos=b, escapeinside={\%*}{*)} } \begin{lstlisting}[caption={SPSS 代码示例},label={lst:spss}] * Descriptive statistics. DESCRIPTIVES VARIABLES=age gender income /STATISTICS=MEAN STDDEV MIN MAX. \end{lstlisting} ``` 这会在文档生成一个带有 SPSS 代码的框,并为其添加标签和标题。 2. MATLAB 代码 同样,使用 `listings` 宏包也可以在 LaTeX 输入 MATLAB 代码。以下是一个例子: ```latex \usepackage{listings} \lstset{ language=Matlab, basicstyle=\ttfamily, keywordstyle=\bfseries, commentstyle=\itshape, stringstyle=\ttfamily, showstringspaces=false, breaklines=true, numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt, backgroundcolor=\color{gray!10}, frame=single, rulecolor=\color{black!30}, captionpos=b, escapeinside={\%*}{*)} } \begin{lstlisting}[caption={MATLAB 代码示例},label={lst:matlab}] % Generate a vector of random numbers. x = randn(1,100); % Plot the vector. plot(x); \end{lstlisting} ``` 这会在文档生成一个带有 MATLAB 代码的框,并为其添加标签和标题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值