Redian新闻
>
使用 LaTeX 创建优美的 PDF 文件 | Linux 中国

使用 LaTeX 创建优美的 PDF 文件 | Linux 中国

科技
 
导读:使用 LaTeX 标记语言来撰写文档。                                         
本文字数:6084,阅读时长大约:7分钟

使用 LaTeX 标记语言来撰写文档。

LaTeX 文件准备系统有一段有趣的历史。在 1968 年,程序员 Don Knuth 用一种老式印刷排版方式,撰写了他的第一本书《计算机程序设计艺术(The Art of Computer Programming)》。当他在 1976 年出版第二版时,出版商已经转向现代照相排版技术。

Knuth 对新版本的外观不满意。他从程序员的角度解决问题,决定创建他自己的文字处理系统,这样以后他出版的书就可以以相同格式排版,拥有相同的外观。因此,Don Knuth 在 1978 年编写了第一版 TeX 。

几年后,Leslie Lamport 创建了一组宏定义,以便作者更容易编写复杂文档。Lamport 的宏定义扩展,即 LaTeX,有效地扩展了 TeX 能够轻松创建各种文档。例如,许多学术组织使用 LaTeX 出版期刊和论文集。

使用 LaTeX 编写文档

通过写一些短文就可以很容易掌握 LaTeX 基础。让我们从 Opensource.com🔗 opensource.com 介绍页面借用一下内容,创建一个示例:

  1. $ cat about.tex
  2. \documentclass{article}
  3. \begin{document}
  4. Opensource.com is a premier, daily publication focused on
  5. open source and Linux tutorials, stories, and resources.
  6. We're a diverse and inviting group, made up of staff
  7. editors, Correspondents, contributors, and readers. We
  8. value differences in skills, talents, backgrounds, and
  9. experiences. There are a few different ways to get involved
  10. as a reader or a writer.
  11. \end{document}

类似其他文档格式程序, LaTeX 会将单词汇集起来,填充成段落 。这意味着你可以在段落中间添加新文本,而不用担心最终文档的段落参差不齐。只要你不在段落中添加空行, LaTeX 就会创建完全对齐的段落。当它找到一个空行时, LaTeX 会开启一个新段落。

LaTeX 需要一些定义文档的控制语句。任何 LaTeX 文档应当以“文档类别”声明开始。LaTeX 支持多种文档,包括书信、书籍和文章。例如,我使用 \documentclass{article} 设置类别为 “文章” 。

使用 \begin{document} 和 \end{document} 声明来定义文本的开始和结束。如果你在 \begin{document} 前添加了文本,那么 LaTeX 会报错。在 \end{document} 之后的文本都会被忽略。

使用 LaTeX 的 latex 命令处理文档:

  1. $ latex about.tex
  2. This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=latex)
  3. restricted \write18 enabled.
  4. entering extended mode
  5. (./about.tex
  6. LaTeX2e <2020-10-01> patch level 4
  7. (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
  8. Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
  9. (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
  10. (/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)
  11. No file about.aux.
  12. [1] (./about.aux) )
  13. Output written on about.dvi (1 page, 736 bytes).
  14. Transcript written on about.log.

LaTeX 会输出许多文本,这样你就可以知道它在干什么。若你的文档包含错误, LaTeX 会报错并提示它可以做什么。大多数情况下,你可以在提示后输入 exit 来强制退出 LaTeX 。

如果用 LaTeX 成功生成一个文档,会生成一个带 .dvi 后缀的文件。DVI 表示 “设备无关(Device Independent)”,因为你可以使用不同的工具来生成其他格式。例如, dvipdf 程序可以将 DVI 文件转换为 PDF 文件。

  1. $ dvipdf about.dvi

LaTeX output

添加列表

LaTeX 支持两种列表:一种以数字开头的 “枚举” 列表,一种 “逐项” 或 “项目符号” 列表。在第二段后添加一个简短的枚举列表,列出人们可以参与 Opensource.com🔗 Opensource.com 的方式:

  1. \begin{enumerate}
  2. \item Be a writer
  3. \item Be a reader
  4. \end{enumerate}

与在文档定义中添加 \begin 和 \end 声明类似,你也需要在列表前后添加 \begin 和 \end 声明。在列表中,每个项目以 \item 命令开始。当你用 LaTeX 处理该文档并转换为 PDF 格式后,你会看到该列表为数字列表:

LaTeX output

你也可以在列表中嵌套列表。这是一个优雅的功能,如果你需要在列表中为每个条目添加选项。例如,你可以为想要在 Opensource.com🔗 Opensource.com 中成为作者的人们提供一些不同的资源。嵌入列表使用单独的 \begin 和 \end 声明。为了看起来方便,我在示例中添加了空行,但是 LaTeX 会忽略这些空行:

  1. \begin{enumerate}
  2. \item Be a writer
  3.   \begin{itemize}
  4.   \item Resources for writers
  5.   \item Contributor Club
  6.   \item Correspondent Program
  7.   \end{itemize}
  8. \item Be a reader
  9. \end{enumerate}

作为嵌套列表,新列表嵌入在编号 1 的项目中,因为你在原先的 \item 声明之间添加了列表。你可以通过在 \end{enumerate} 语句前添加新列表,作为编号 2 项目的嵌套列表。

LaTeX output

章节和小节

你可以将冗长文章分成多个章节,这样更易于阅读。使用 \section{...} 语句在大括号内添加章节标题。例如,你可以在文档顶部添加一个标题为 “AboutOpensource.com🔗 Opensource.com” 的新章节:

  1. $ head about.tex
  2. \documentclass{article}
  3. \begin{document}
  4. \section{About Opensource.com}
  5. Opensource.com is a premier, daily publication focused on
  6. open source and Linux tutorials, stories, and resources.
  7. We're a diverse and inviting group, made up of staff
  8. editors, Correspondents, contributors, and readers. We

article 文档类会在每个主要章节添加编号,并使字体变大来突出显示。

LaTeX output

你可以使用 \subsection{...} 命令来组织文档。就像 \section{...} 命令一样,在大括号中输入副标题名称。

  1. $ head about.tex
  2. \documentclass{article}
  3. \begin{document}
  4. \section{About Opensource.com}
  5. Opensource.com is a premier, daily publication focused on
  6. open source and Linux tutorials, stories, and resources.
  7. \subsection{Welcome to the Opensource.com community}

LaTeX output

标题和作者

用于出版的科学类的文章需要标题、作者以及发表日期。LaTeX 提供了通过插入命令的方式来添加这些信息,然后使用单独的 \maketitle 命令生成文章的标题。

将 “About Us” 作为文章标题,作者为 “Opensource.com🔗 Opensource.com Editors”,发表日期为 “July 10, 2022” 。你必须在 \begin{document} 之后,文章内容前插入这些内容。

  1. \title{About Us}
  2. \author{Opensource.com Editors}
  3. \date{July 10, 2022}
  4. \maketitle

当你在生成文档时,LaTeX 会将标题、作者和日期添加到文章的顶部:

LaTeX output

着重强调

科学和其他技术类文章通常会突出术语和短语。LaTeX 提供了几种可以在技术文档中使用的字体效果,包括强调文本(通常以斜体显示)、粗体文本和小型大写字母(small caps)

将短语“staff editors, Correspondents, contributors, and readers”放在斜体文本中,并将特定词“reader”和“writer”放在段落后面的强调文本中。你也可以将“skills, talents, backgrounds, and experiences”加粗。虽然这不是正确的样式设置方式,但你可以使用小型大写字母来键入 “Linux” 。

  1. $ head -20 about.tex
  2. \documentclass{article}
  3. \begin{document}
  4. \title{About Us}
  5. \author{Opensource.com Editors}
  6. \date{July 10, 2022}
  7. \maketitle
  8. \section{About Opensource.com}
  9. Opensource.com is a premier, daily publication focused on
  10. open source and \textsc{Linux} tutorials, stories, and resources.
  11. \subsection{Welcome to the Opensource.com community}
  12. We're a diverse and inviting group, made up of \textit{staff
  13. editors, Correspondents, contributors, and readers}. We
  14. value differences in \textbf{skills, talents, backgrounds, and
  15. experiences}. There are a few different ways to get involved
  16. as a \emph{reader} or a \emph{writer}.

该示例展示了不同样式的文本的应用方法。当你需要强调时,使用 \emph{...} 命令,将强调主题放在大括号内。要以斜体、粗体或小型大写字母显示文本,使用 \text 命令的变体:\textit{...} 用于斜体,\textbf{...} 用于粗体,以及 \ textsc{...} 用于小型大写字母。LaTeX 支持许多其他方式来设置文本样式,这些样式有助于你编写科学技术类文章。

LaTeX output

使用 LaTeX

我只是介绍了使用 LaTeX 撰写科学技术文章的几种方式。你也可以在 LaTeX 中添加脚注,进行数学公式和方程的排版,取决于你的需求。你也可以通过阅读 Opensource.com🔗 Opensource.com 中的文章 《在 LaTeX 中创建文档的介绍》🔗 opensource.com ,了解使用 LaTeX 撰写科学技术文章的其他方式。


via: https://opensource.com/article/22/8/pdf-latex

作者:Jim Hall 选题:lkxed 译者:Donkey 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出


LCTT 译者 :Donkey
🌟🌟🌟
翻译: 16.0 篇
|
贡献: 71 天
2022-06-09
2022-08-19
https://linux.cn/lctt/Donkey-Hao
欢迎遵照 CC-BY-SA 协议规定转载,
如需转载,请在文章下留言 “转载:公众号名称”,
我们将为您添加白名单,授权“转载文章时可以修改”。

微信扫码关注该文公众号作者

戳这里提交新闻线索和高质量文章给我们。
相关阅读
用 ranger 在 Linux 终端管理你的文件 | Linux 中国如何使用 Linux sed 命令自动进行文件编辑 | Linux 中国在 Linux 中使用组合键输入隐藏的字形 | Linux 中国夏日芝加哥的别样风情现在的日子就得这么个过法微软决定放弃 Teams 的 Linux 应用,而用渐进式网页应用取代 | Linux 中国修复 Ubuntu 中的 “Pending Update of Firefox snap” 错误 | Linux 中国在 Linux 上使用 Rhythbox 听音乐 | Linux 中国在 Linux 中创建 LVM 分区的分步指南 | Linux 中国又有 Linux 开发者加入微软,这次是 systemd 的创建者 | Linux 中国用这些开源工具在 Linux 上编辑 PDF 文件 | Linux 中国如何编写 C 程序在 Linux 上创建音乐播放列表 | Linux 中国如何使用 Dockerfile 创建自定义 Docker 镜像 | Linux 中国大家别紧张,美国没有禁止堕胎在 Linux 上使用 Bash 创建一个临时文件 | Linux 中国如何在 Ubuntu/Linux 和 Windows 之间共享文件夹 | Linux 中国如何在 Linux 中使用 Pandoc 转换文件格式 | Linux 中国如何在 Linux 中实时监控日志文件(桌面和服务器) | Linux 中国神秘的 GeckoLinux 创建者推出了一个新的 Debian 合成发行版 | Linux 中国准备好在 Debian Linux 上获得 Ubuntu MATE 的体验吧! | Linux 中国在 Linux 中使用 Etcher 创建可启动 USB – 下载和使用指南 | Linux 中国System 76 将不会发布 Pop!_OS 22.10 Linux 发行版 | Linux 中国Linux inxi 命令的 3 种使用方法 | Linux 中国在 Linux 中隐藏文件和文件夹的那些事 | Linux 中国使用 Podman Desktop 在 Fedora Linux 上管理容器 | Linux 中国使用 OpenSMTPD 将邮件中继到多个 smarthost | Linux 中国关于 Linux 和 Git 的创造者 Linus Torvalds 的 20 件趣事 | Linux 中国我如何使用现场 USB 设备恢复我的 Linux 系统 | Linux 中国检查 Linux 磁盘使用情况 | Linux 中国中国律师张思之逝世我是如何使用 Linux fmt 命令来格式化文本 | Linux 中国教育随笔(95)临阵磨刀亮三分,指导有法得实惠如何在 Linux 中使用媒体传输协议访问安卓设备的内部存储和 SD 卡 | Linux 中国开源朗读者:使用 Linux 的优势和劣势 | Linux 中国GNOME “文件”引入最受欢迎的功能:“新建文件”菜单 | Linux 中国
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。