Journey of Latex

Journey of Latex

Journey of Latex APA 的格式 APA Citation 需要使用 biber, 而不是 bibtex。在开头放: \usepackage[style=apa,backend=biber]{biblatex} \DeclareLanguageMapping{american}{am

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%"
        ]
    }
]

结束

在Neovim里配置Latex

要配置 vimtex,只需要在 lazyvim里安装这个插件就行了。在macos上我用的PDF reader 是skim

关键在于如何配置反向搜索,在tex文件很大的时候这个还是挺有用的。这篇文章可能有用: link。注意,我的 lazyvim用的是 lua,所以需要把他的脚本修改成 lua

-- lua/vimtex_server.lua (or anywhere in your config)

local function write_server_name()
  -- Choose temp dir (match Vimscript logic)
  local tmpdir
  if vim.fn.has("win32") == 1 then
    tmpdir = vim.env.TEMP or vim.fn.stdpath("cache")
  else
    tmpdir = "/tmp"
  end
  local outfile = tmpdir .. "/vimtexserver.txt"

  -- Ensure we actually have a servername (Neovim sets this only if started with --listen or similar)
  local server = vim.v.servername
  if not server or server == "" then
    -- Start an RPC server so vim.v.servername gets populated
    -- Using a unique socket path/name under the temp dir
    local name = vim.fn.tempname()
    vim.fn.serverstart(name)
    server = vim.v.servername
  end

  -- Write the server name to file (as a one-line list of strings)
  vim.fn.writefile({ server }, outfile)
end

-- Create the autocmd: run for TeX buffers
local grp = vim.api.nvim_create_augroup("vimtex_common", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
  group = grp,
  pattern = "tex",
  callback = write_server_name,
})

就可以了。

Comment