本文深入探讨如何使用(主要是)Markdown 语法撰写研究论文。我们将介绍如何创建和引用章节、图表(在 Markdown 和 LaTeX 中)以及参考文献。我们还将讨论棘手的情况,以及为什么在 LaTeX 中编写它们是正确的方法。
研究
研究论文通常包含对章节、图表、表格和参考文献的引用。Pandoc 本身不能轻易地交叉引用这些内容,但它可以利用 pandoc-crossref 过滤器来自动编号和交叉引用章节、图表和表格。
让我们首先重写 一篇教育研究论文的示例,该论文最初用 LaTeX 编写,并使用 Pandoc 和 pandoc-crossref 在 Markdown(和一些 LaTeX)中重写。
添加和引用章节
章节自动编号,必须使用 Markdown 标题 H1 编写。子章节使用子标题 H2-H4 编写(通常不需要更多)。例如,要编写标题为“Implementation”的章节,请写入 # Implementation {#sec:implementation}
,Pandoc 将生成 3. Implementation
(或相应的编号章节)。标题“Implementation”使用标题 H1 并声明一个标签 {#sec:implementation}
,作者可以使用该标签引用该章节。要引用章节,请键入 @
符号,后跟章节标签,并用方括号括起来:[@sec:implementation]
。
在这篇论文中,我们找到以下示例
we lack experience (consistency between TAs, [@sec:implementation]).
Pandoc 生成:
we lack experience (consistency between TAs, Section 4).
章节自动编号(这在文章末尾的 Makefile
中介绍)。要创建未编号的章节,请键入章节标题,后跟 {-}
。例如,### Designing a game for maintainability {-}
创建一个标题为“Designing a game for maintainability”的未编号子章节。
添加和引用图表
添加和引用图表类似于引用章节和添加 Markdown 图像
{#fig:scatter-matrix}
上面的行告诉 Pandoc,存在一个标题为散点图矩阵的图表,图像的路径是 data/scatterplots/RScatterplotMatrix2.png
。{#fig:scatter-matrix}
声明了用于引用该图表的名称。
这是一个示例论文中的图表引用示例
The boxes "Enjoy", "Grade" and "Motivation" ([@fig:scatter-matrix]) ...
Pandoc 生成以下输出:
The boxes "Enjoy", "Grade" and "Motivation" (Fig. 1) ...
添加和引用参考文献
大多数研究论文将参考文献保存在 BibTeX 数据库文件中。在本例中,该文件名为 biblio.bib,其中包含论文的所有参考文献。以下是该文件的外观:
@inproceedings{wrigstad2017mastery,
Author = {Wrigstad, Tobias and Castegren, Elias},
Booktitle = {SPLASH-E},
Title = {Mastery Learning-Like Teaching with Achievements},
Year = 2017
}
@inproceedings{review-gamification-framework,
Author = {A. Mora and D. Riera and C. Gonzalez and J. Arnedo-Moreno},
Publisher = {IEEE},
Booktitle = {2015 7th International Conference on Games and Virtual Worlds
for Serious Applications (VS-Games)},
Doi = {10.1109/VS-GAMES.2015.7295760},
Keywords = {formal specification;serious games (computing);design
framework;formal design process;game components;game design
elements;gamification design frameworks;gamification-based
solutions;Bibliographies;Context;Design
methodology;Ethics;Games;Proposals},
Month = {Sept},
Pages = {1-8},
Title = {A Literature Review of Gamification Design Frameworks},
Year = 2015,
Bdsk-Url-1 = {http://dx.doi.org/10.1109/VS-GAMES.2015.7295760}
}
...
第一行,@inproceedings{wrigstad2017mastery,
,声明了出版物类型 (inproceedings
) 和用于引用该论文的标签 (wrigstad2017mastery
)。
要引用标题为Mastery Learning-Like Teaching with Achievements的论文,请键入
the achievement-driven learning methodology [@wrigstad2017mastery]
Pandoc 将输出:
the achievement- driven learning methodology [30]
我们将生成的论文包含一个参考文献部分,其中包含如下编号的参考文献:

引用文章集合很容易:只需引用每篇文章,使用分号 ;
分隔标记的参考文献。如果有两个标记的参考文献——即 SEABORN201514
和 gamification-leaderboard-benefits
——将它们一起引用,如下所示:
Thus, the most important benefit is its potential to increase students' motivation
and engagement [@SEABORN201514;@gamification-leaderboard-benefits].
Pandoc 将生成:
Thus, the most important benefit is its potential to increase students’ motivation
and engagement [26, 28]
问题案例
一个常见的问题涉及不适合页面的对象。然后,它们会浮动到最适合它们的位置,即使该位置不是读者期望看到的位置。由于当图表或表格出现在提及它们的位置附近时,论文更易于阅读,因此我们需要对这些元素的位置进行一些控制。因此,我建议使用 figure
LaTeX 环境,这使用户能够控制图表的位置。
让我们以上面显示的图表示例为例
{#fig:scatter-matrix}
并在 LaTeX 中重写它
\begin{figure}[t]
\includegraphics{data/scatterplots/RScatterplotMatrix2.png}
\caption{\label{fig:matrix}Scatterplot matrix}
\end{figure}
在 LaTeX 中,figure
环境中的 [t]
选项声明应将图像放置在页面顶部。有关更多选项,请参阅 Wikibooks 文章 LaTex/浮动体、图表和标题。
生成论文
到目前为止,我们已经介绍了如何添加和引用(子)章节和图表,以及引用参考文献——现在让我们回顾一下如何生成 PDF 格式的研究论文。为了生成 PDF,我们将使用 Pandoc 生成一个 LaTeX 文件,该文件可以编译为最终的 PDF。我们还将讨论如何使用自定义模板和元信息文件在 LaTeX 中生成研究论文,以及如何将 LaTeX 文档编译为最终的 PDF 格式。
大多数会议都提供一个 .cls 文件或模板,用于指定论文的外观;例如,它们是否应使用双栏格式和其他设计处理。在我们的示例中,会议提供了一个名为 acmart.cls 的文件。
通常期望作者在其论文中包含他们所属的机构。但是,默认 Pandoc 的 LaTeX 模板中未包含此选项(请注意,可以通过键入 pandoc -D latex
来检查 Pandoc 模板)。要包含单位,请获取默认 Pandoc 的 LaTeX 模板并添加一个新字段。Pandoc 模板被复制到一个名为 mytemplate.tex
的文件中,如下所示:
pandoc -D latex > mytemplate.tex
默认模板包含以下代码
$if(author)$
\author{$for(author)$$author$$sep$ \and $endfor$}
$endif$
$if(institute)$
\providecommand{\institute}[1]{}
\institute{$for(institute)$$institute$$sep$ \and $endfor$}
$endif$
由于模板应包含作者的单位和电子邮件地址等信息,因此我们对其进行了更新以包含这些字段(我们也进行了其他更改,但由于文件长度的原因,此处未包含它们)
latex
$for(author)$
$if(author.name)$
\author{$author.name$}
$if(author.affiliation)$
\affiliation{\institution{$author.affiliation$}}
$endif$
$if(author.email)$
\email{$author.email$}
$endif$
$else$
$author$
$endif$
$endfor$
完成这些更改后,我们应该具有以下文件:
main.md
包含研究论文biblio.bib
包含参考文献数据库acmart.cls
是我们应使用的文档类mytemplate.tex
是要使用的模板文件(而不是默认模板)
让我们在 meta.yaml
文件中添加论文的元信息
---
template: 'mytemplate.tex'
documentclass: acmart
classoption: sigconf
title: The impact of opt-in gamification on `\\`{=latex} students' grades in a software design course
author:
- name: Kiko Fernandez-Reyes
affiliation: Uppsala University
email: kiko.fernandez@it.uu.se
- name: Dave Clarke
affiliation: Uppsala University
email: dave.clarke@it.uu.se
- name: Janina Hornbach
affiliation: Uppsala University
email: janina.hornbach@fek.uu.se
bibliography: biblio.bib
abstract: |
An achievement-driven methodology strives to give students more control over their learning with enough flexibility to engage them in deeper learning. (more stuff continues)
include-before: |
```{=latex}
\copyrightyear{2018}
\acmYear{2018}
\setcopyright{acmlicensed}
\acmConference[MODELS '18 Companion]{ACM/IEEE 21th International Conference on Model Driven Engineering Languages and Systems}{October 14--19, 2018}{Copenhagen, Denmark}
\acmBooktitle{ACM/IEEE 21th International Conference on Model Driven Engineering Languages and Systems (MODELS '18 Companion), October 14--19, 2018, Copenhagen, Denmark}
\acmPrice{XX.XX}
\acmDOI{10.1145/3270112.3270118}
\acmISBN{978-1-4503-5965-8/18/10}
\begin{CCSXML}
<ccs2012>
<concept>
<concept_id>10010405.10010489</concept_id>
<concept_desc>Applied computing~Education</concept_desc>
<concept_significance>500</concept_significance>
</concept>
</ccs2012>
\end{CCSXML}
\ccsdesc[500]{Applied computing~Education}
\keywords{gamification, education, software design, UML}
```
figPrefix:
- "Fig."
- "Figs."
secPrefix:
- "Section"
- "Sections"
...
此元信息文件在 LaTeX 中设置以下变量:
template
指的是要使用的模板 ('mytemplate.tex')documentclass
指的是要使用的 LaTeX 文档类 (acmart
)classoption
指的是类的选项,在本例中为sigconf
title
指定论文的标题author
是一个对象,其中包含其他字段,例如name
、affiliation
和email
。bibliography
指的是包含参考文献的文件 (biblio.bib)abstract
包含论文的摘要include-before
是要包含在论文实际内容之前的信息;这在 LaTeX 中称为前言。我在此处包含它以展示如何生成计算机科学论文,但您可以选择跳过它figPrefix
指定如何在文档中引用图表,即,当引用图表[@fig:scatter-matrix]
时应显示什么。例如,当前的figPrefix
在示例The boxes "Enjoy", "Grade" and "Motivation" ([@fig:scatter-matrix])
中生成此输出:The boxes "Enjoy", "Grade" and "Motivation" (Fig. 3)
。如果有多个图表,则当前设置声明应改为在图表编号旁边显示Figs.
。secPrefix
指定如何在文档中其他位置引用章节(类似于上面描述的图表)
现在元信息已设置,让我们创建一个 Makefile
,以生成所需的输出。此 Makefile
使用 Pandoc 生成 LaTeX 文件,使用 pandoc-crossref
生成交叉引用,使用 pdflatex
将 LaTeX 编译为 PDF,并使用 bibtex
处理参考文献。
Makefile
如下所示:
all: paper
paper:
@pandoc -s -F pandoc-crossref --natbib meta.yaml --template=mytemplate.tex -N \
-f markdown -t latex+raw_tex+tex_math_dollars+citations -o main.tex main.md
@pdflatex main.tex &> /dev/null
@bibtex main &> /dev/null
@pdflatex main.tex &> /dev/null
@pdflatex main.tex &> /dev/null
clean:
rm main.aux main.tex main.log main.bbl main.blg main.out
.PHONY: all clean paper
Pandoc 使用以下标志:
-s
创建独立的 LaTeX 文档-F pandoc-crossref
使用过滤器pandoc-crossref
--natbib
使用natbib
渲染参考文献(您也可以选择--biblatex
)--template
设置要使用的模板文件-N
对章节标题进行编号-f
和-t
指定从哪种格式转换为哪种格式。-t
通常包含格式,后跟使用的 Pandoc 扩展。在示例中,我们声明了raw_tex+tex_math_dollars+citations
,以允许在 Markdown 文件中间使用raw_tex
LaTeX。tex_math_dollars
使我们能够像在 LaTeX 中一样键入数学公式,而citations
使我们能够使用 此扩展。
要从 LaTeX 生成 PDF,请遵循 bibtex 的指南来处理参考文献
@pdflatex main.tex &> /dev/null
@bibtex main &> /dev/null
@pdflatex main.tex &> /dev/null
@pdflatex main.tex &> /dev/null
该脚本包含 @
以忽略输出,我们将标准输出和错误的文件句柄重定向到 /dev/null
,这样我们就看不到执行这些命令生成的输出。
最终结果如下所示。可以在 GitHub 上找到本文的存储库

结论
在我看来,研究的全部意义在于协作、传播思想以及改进任何领域的现有技术水平。大多数计算机科学家和工程师使用 LaTeX 文档系统撰写论文,该系统为数学提供了出色的支持。社会科学研究人员似乎坚持使用 DOCX 文档。
当来自不同社区的研究人员一起撰写论文时,他们应首先讨论他们将使用的格式。虽然 DOCX 对于涉及数学的工程师来说可能不方便,但 LaTeX 对于缺乏编程背景的研究人员来说可能很麻烦。正如本文所示,Markdown 是一种易于使用的语言,工程师和社会科学家都可以使用它。
3 条评论