使用 LaTeX 和 TeXstudio 排版文檔
LaTeX 是一個服務(wù)于高質(zhì)量排版的文檔準(zhǔn)備系統(tǒng)。通常用于大量的技術(shù)和科學(xué)文檔的排版。不過,你也可以使用 LaTex 排版各種形式的文檔。教師可以編輯他們的考試和教學(xué)大綱,學(xué)生可以展示他們的論文和報告。這篇文章讓你嘗試使用 TeXstudio。TeXstudio 是一個便于編輯 LaTeX 文檔的軟件。
啟動 TeXstudio
如果你使用的是 Fedora Workstation,請啟動軟件管理,然后輸入 TeXstudio 以搜索該應(yīng)用程序。然后選擇安裝并添加 TeXstudio 到你的系統(tǒng)。你可以從軟件管理中啟動這個程序,或者像以往一樣在概覽中啟動這個軟件。
或者,如果你使用終端,請輸入 texstudio
。如果未安裝該軟件包,系統(tǒng)將提示你安裝它。鍵入 y
開始安裝。
$ texstudio
bash: texstudio: command not found...
Install package 'texstudio' to provide command 'texstudio'? [N/y] y
你的第一份文檔
LaTeX 命令通常以反斜杠 \
開頭,命令參數(shù)用大括號 {}
括起來。首先聲明 documentclass
的類型。這個例子向你展示了該文檔的類是一篇文章。
然后,在聲明 documentclass
之后,用 begin
和 end
標(biāo)記文檔的開始和結(jié)束。在這些命令之間,寫一段類似以下的內(nèi)容:
\documentclass{article}
\begin{document}
The Fedora Project is a project sponsored by Red Hat primarily to co-ordinate the development of the Linux-based Fedora operating system, operating with the vision that the project "creates a world where free culture is welcoming and widespread, collaboration is commonplace, and people control their content and devices". The Fedora Project was founded on 22 September 2003 when Red Hat decided to split Red Hat Linux into Red Hat Enterprise Linux (RHEL) and a community-based operating system, Fedora.
\end{document}
使用間距
要創(chuàng)建段落分隔符,請在文本之間保留一個或多個換行符。下面是一個包含四個段落的示例:
從該示例中可以看出,多個換行符不會在段落之間創(chuàng)建額外的空格。但是,如果你確實需要留出額外的空間,請使用 hspace
和 vspace
命令。這兩個命令分別添加水平和垂直空間。下面是一些示例代碼,顯示了段落周圍的附加間距:
\documentclass{article}
\begin{document}
\hspace{2.5cm} The four essential freedoms
\vspace{0.6cm}
A program is free software if the program's users have the 4 essential freedoms:
The freedom to run the program as you wish, for any purpose (freedom 0).\vspace{0.2cm}
The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.\vspace{0.2cm}
The freedom to redistribute copies so you can help your neighbour (freedom 2).\vspace{0.2cm}
The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.
\end{document}
如果需要,你也可以使用 noindent
命令來避免縮進。這里是上面 LaTeX 源碼的結(jié)果:
使用列表和格式
如果把自由軟件的四大基本自由列為一個清單,這個例子看起來會更好。通過在列表的開頭使用\begin{itemize}
,在末尾使用 \end{itemize}
來設(shè)置列表結(jié)構(gòu)。在每個項目前面加上 \item
命令。
額外的格式也有助于使文本更具可讀性。用于格式化的有用命令包括粗體、斜體、下劃線、超大、大、小和 textsc 以幫助強調(diào)文本:
\documentclass{article}
\begin{document}
\hspace{2cm} {\huge The four essential freedoms}
\vspace{0.6cm}
\noindent {\large A program is free software if the program's users have the 4 essential freedoms}:
\begin{itemize}
\item \vspace{0.2cm}
\noindent \textbf{The freedom to run} the program as you wish, for any purpose \textit{(freedom 0)}. \vspace{0.2cm}
\item \noindent \textbf{The freedom to study} how the program works, and change it so it does your computing as you wish \textit{(freedom 1)}. Access to the source code is a precondition for this.\vspace{0.2cm}
\item \noindent \textbf{The freedom to redistribute} copies so you can help your neighbour \textit{(freedom 2)}.\vspace{0.2cm}
\item \noindent \textbf{The freedom to distribute copies of your modified versions} to others \textit{(freedom 3)}. \tiny{By doing this you can give the whole community a chance to benefit from your changes.\underline{\textsc{ Access to the source code is a precondition for this.}}}
\end{itemize}
\end{document}
添加列、圖像和鏈接
列、圖像和鏈接有助于為文本添加更多信息。LaTeX 包含一些高級功能的函數(shù)作為宏包。\usepackage
命令加載宏包以便你可以使用這些功能。
例如,要使用圖像,可以使用命令 \usepackage{graphicx}
。或者,要設(shè)置列和鏈接,請分別使用 \usepackage{multicol}
和 \usepackage{hyperref}
。
\includegraphics
命令將圖像內(nèi)聯(lián)放置在文檔中。(為簡單起見,請將圖形文件包含在與 LaTeX 源文件相同的目錄中。)
下面是一個使用所有這些概念的示例。它還使用下載的兩個 PNG 圖片。試試你自己的圖片,看看它們是如何工作的。
\documentclass{article}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{hyperref}
\begin{document}
\textbf{GNU}
\vspace{1cm}
GNU is a recursive acronym for "GNU's Not Unix!", chosen because GNU's design is Unix-like, but differs from Unix by being free software and containing no Unix code.
Richard Stallman, the founder of the project, views GNU as a "technical means to a social end". Stallman has written about "the social aspects of software and how Free Software can create community and social justice." in his "Free Society" book.
\vspace{1cm}
\textbf{Some Projects}
\begin{multicols}{2}
Fedora
\url{https://getfedora.org}
\includegraphics[width=1cm]{fedora.png}
GNOME
\url{https://getfedora.org}
\includegraphics[width=1cm]{gnome.png}
\end{multicols}
\end{document}
這里的功能只觸及 LaTeX 功能的表面。你可以在該項目的幫助和文檔站點了解更多關(guān)于它們的信息。