Journey of Latex

APA 的格式

APA Citation

需要使用 biber, 而不是 bibtex。在开头放:

\usepackage[style=apa,backend=biber]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\addbibresource{references.bib}

\end{document}之前加上 \printbibliography即可。

\maketitle error

Overleaf上的 apa模板中,要求封面有很多内容,很多情况下是我们不希望有。但是如果留空会有问题。这个时候,填入 ~即可:

\title{My title} 
\shorttitle{My short title} 
\author{Chixiyu}
\duedate{~}
\affiliation{} % This one can be blank idk why
\course{Computer Science} 
\professor{~}
\begin{document}
\maketitle

这样不会报错。

如果删除 \professor{}这行,pdf中会出现“Your professor"占位符。如果放入 \professor{},则报错(overleaf上倒是可以这么操作)。

Table of Contents

加入代码

如果不是在 Overleaf而是在本地编译的话,可以使用 minted包,支持语法高亮。

  1. 需要安装依赖:
pip install Pygments
  1. 正文前面加入
\usepackage{minted}
\setminted{
  linenos=true,
  breaklines=true,
  fontsize=\small,
  baselinestretch=1.0
}
  1. 正文中写:
\begin{minted}[java] % java can be any other programming language
System.out.println("Hello World")
\end{minted}
  1. 如果使用的是 vscode,需要在设置的 JSON里面修改编译 Latex的指令,加入 -shell-escape参数。这是因为 minted需要使用 Pygment的程序来语法高亮,Latex本身因为安全问题不会允许执行外部程序,所以要加入这一行。

具体原理是:

  1. LaTeX encounters code block
  2. Calls pygmentize (external program)
  3. Pygmentize processes the code
  4. Returns highlighted code to LaTeX‘

除了 xelatex如果使用 pdflatex也可以按照类似的方法修改(多加一样即可),本例使用的是 xelatex

"latex-workshop.latex.tools": [
    ...,
    {
        "name": "xelatex",
        "command": "xelatex",
        "args": [
            "-shell-escape",
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "%DOC%"
        ]
    }
]

结束