Journey of Latex
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
包,支持语法高亮。
- 需要安装依赖:
pip install Pygments
- 正文前面加入
\usepackage{minted}
\setminted{
linenos=true,
breaklines=true,
fontsize=\small,
baselinestretch=1.0
}
- 正文中写:
\begin{minted}[java] % java can be any other programming language
System.out.println("Hello World")
\end{minted}
- 如果使用的是
vscode
,需要在设置的JSON
里面修改编译Latex
的指令,加入-shell-escape
参数。这是因为minted
需要使用Pygment
的程序来语法高亮,Latex
本身因为安全问题不会允许执行外部程序,所以要加入这一行。
具体原理是:
- LaTeX encounters code block
- Calls pygmentize (external program)
- Pygmentize processes the code
- 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%"
]
}
]
结束
评论
其他文章