初識 LaTeX#
TODO:LaTeX の意味、用途、インストール
tex 文書のコンパイル
xelatex gougu.tex % 初回コンパイル
bibtex gougu.aux % 引用を生成
xelatex gougu.tex % 再コンパイル、引用を追加
いくつかの tex ソースコードの例
\maketitle % タイトルを生成
\tableofcontents % TOC を生成(少なくとも二回コンパイルする必要があります)
\usepackage{graphicx} % パッケージを使用
\includegraphics[width=3cm]{input.pdf} % 他の画像フォーマットも使用可能:.png, .jpg, .eps など
\hline % 水平線(表に使用)
% 環境
\begin{figure}[ht] % ここにトップ(画像の浮動位置設定)
\centering
\includegraphics[scale=0.6]{xiantu.pdf} \caption{これは画像の説明です。} % xiantu.pdf は画像で、他のフォーマットも使用可能
\label{fig:xiantu} % label は文中の説明引用に使用
\end{figure}
いくつかのパッケージの説明#
- fontenc % フォントエンコーディング
- fontspec
- ccfonts % コンクリート
英字文字でギリシャ文字を指定
\usepackage[greek,english]{babel}
\greektext{abcde}
TODO:fontenc、inputenc
Q\@.E\@.D\@. つまり「証明完了」。 % \@. (略語の中のピリオドが文の終わりのピリオドと見なされないように)
\CJKsetecglue{} % e(nglish) c(hinese) グルーを「ノーグルー」に設定
\phantom{うん} % プレースホルダーですが、内容は表示されません
\vphantom % \phantom に似ています
\hphantom % \phantom に似ています
\\ % 改行、`\\linebreak` も使用可能
\par
{\You {\emph should} emphasis it.}
\textit{
You {\emph should} emphasis it.}
\newcommand\Emph{\textbf}
\underline % テキストを下線付きで表示
\S
\dag
\ddag % ダブルダガー
\texttrademark % テキストなしはテキストモードと数式モードの両方で使用可能
% シンボル
\symbol{'\$} % WYSIWYG
\symbol{'Z}
\symbol{"6a} % #hex(16進数)
\symbol{'07} % #oct(8進数)
% フォントファミリー
\textrm{text in Roman Family} \rmfamily
\textsf{text in Sans Serif font Family} \sffamily
\texttt{text in Typewritter font family} \ttfamily % t(ypewritter) t(ext)
% フォント形状
\textup{text in Upright shape} \upshape
\textit{text in Italic shape} \itshape
\textsl{text in Slanted shape} \slshape
\textsc{text in Small Capital} \scshape % 小キャプション
% フォントシリーズ
\textmd{median text} \mdseries
\textbf{bold face} \bfseries
% デフォルト設定
\rmfamily\mdseries\upshape
% CJK フォントファミリー
{\CJKfamily{hei}これは黒体です}
{\CJKfamily{kai}これは楷書です}
{\CJKfamily{song}これは宋体です}
{\CJKfamily{fs}これは仿宋です}
{\songti 宋体}
{\heiti 黒体}
{\fangsong 仿宋}
{\kaishu 楷書}
フォントについて
- New Font Selection Scheme (NFSS)
- フォントエンコーディング
- OT1
- T1
- OML
- OMS
- OMX
- U
- その他
- フォントファミリー
- cmr
- cmss
- cmtt
- cmm
- cmsy
- cmex
- フォントシリーズ
- m
- b
- bx
- sb
- c
- フォント形状
-
n
-
it
-
sl
-
sc
-
フォントを設定
% フォントを設定 --- 方法 1
\fontencoding{OT1}\fontfamily{pzc}\fontseries{mb}\fontshape{it}\fontsize{14}{17} % サイズ、行
\selectfont % 効力を持たせる
So far so good
% フォントを設定 --- 方法 2
\usefont{T1}{pbk}{db}{n} % エンコーディング、ファミリー、シリーズ、形状
Not too bad
txfonts
\documentclass{article}
\usepackage{txfonts} % 無料、優れた
\begin{document}
\end{document}
fontspec
% \setmainfont[<optional>]{<font-name>}
% setmainfont, setsansfont, setmonofont
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Verdana}
\setmonofont{Courier New}
フォント
- Type 1
- TrueType
- OpenType
% フォントのサイズ
\tiny
\scriptsize
\footnotesize
\small
\large
\Large
\LARGE
\huge
\Huge
% 中国語フォントサイズ
\zihao{0} % 初号
\zihao{-0} % 小初号
\zihao{5} % 五号 (c5size)
\zihao{-5} % 小五号 (cs5size)
% デフォルトフォントサイズ
\normalfont % 10pt、または c5size(CTeX)
% 行
\linespread{<因子>} % 基本行間の倍数
\setstretch % スペーシング
\singlespacing
\onehalfspacing
\doublespacing
寸法
pt
ポイントpc
ピカ(12 pt)in
インチ(72.27 pt, 72 bp)bp
ビッグポイントcm
センチメートル(2.54 cm = 1 in)mm
ミリメートルdd
ディドポイントcc
シセロsp
スケールポイント(65536 sp = 1 pt)em
M の幅(\quad
と等しい)ex
x の高さen
スペース
% 改行できない水平間隔
\thinspace \, % 数字用:1\,234\,567\,890
\negthinspace \!
\enspace % 0.5 em
\nobreakable ~ % タイ、名前用:Donald~E. Knuth
% 改行可能な水平間隔
\quad % 1 em
\qquad % 2 em
\enskip % 0.5 em
\ % スペース
% hspace
\hspace{2em} % Space\hspace{1cm}1\,cm,
\hspace*{1cm}Text
\hspace{2em plus 1em minus 0.25 em}
left\hspace{\fill}middle\hfill right % 左、中央、右に揃える
left\hspace{\stretch{2}}middle\hspace{\fill}right
\hrulefill % 下線
\dotfill % 点
% 長さ
\setlength{\parindent}{8em}
\addtolength{\parindent}{2em}
\newlength\mylen % 新しい長さを作成
ボックス
% mbox makebox
\mbox{broken cannot}
\makebox[1em]{\textbullet}text
\makebox[5cm][s]{some text} % 幅、位置(clrs: center, left, right, stretched)
\makebox[0pt][l]{abc}xyz % overlap
abc\llap{xyz} % llap(より高いレベルの表現)
\rlap{abc}xyz % rlap
% fbox framebox
\fbox % \setlength{\fboxsep}{2pt}, \framebox % \fbox より強力で、カスタマイズ可能
\fboxrule{0.4pt} (デフォルト)
% sbox savebox
\sbox \savebox
\newsavebox{\mybox}
\sbox{\mybox}{a box made by me}
\usebox{\mybox}
% ボックスパラメータを設定
\settowidth{10pt}{content}
\settoheight{10pt}{content}
\settodepth{10pt}{content}
% ボックスパラメータを取得
\wd{\fbox}
\ht{\mbox}
\dp{\mybox}
\framebox[2\width]{文字幅の2倍の幅} % 幅、高さ、深さ、合計高さ
整列
\indent % インデントを生成(\parindent)
% 段落
\parskip % 0pt plus 1pt
\setlength{\parskip}{0pt}
\raggedright % 右側が揃っていない
\raggedleft
\centering
\begin{center} % または `flushright`, `flushleft`
中央
\end{center}
その他
% hyphenation を導言区に置く
\hyphenation{man-u-script com-pu-ter gym-na-sium}
% Lettrine 首字母超大多行效果
\usepackage{lettrine}
\lettrine{S}{tay} hungry, stay foolish
% shapepar
\usepackage{shapepar}
\heartpar{この段落のテキストはハート型になります}
% syntonly
\usepackage{syntonly} % 構文のみ
\syntaxonly
% 引用
\begin{quote}
quot
\end{quote}
% 引用 段首縮進
\begin{quotation}
Better for multiparagraph quotation
\end{quotation}
% 詩
\begin{verse}
For Poetry
\end{verse}
% 抽象
\begin{abstract} % article, report
抽象はここにあります % \abstractname 抽象名
% \CTEXoptions[abstractname={摘\quad 要}]
\end{abstract}
リスト
% enumerate
\begin{enumerate} % 番号付き
\item one
\item two
\end{enumerate}
\begin{enumerate}
\item 中文
\item[1a.] 汉语 % 手動で「弾丸」を設定
\end{enumerate}
% itemize
\begin{itemize} % 弾丸
\item not one
\item not two
\end{itemize}
% description
\begin{description} %
\item[\tau] ギリシャ文字アルファベット \tau
\end{description}
% 手動設定
% counter
\item This is number\theenumi % enumi, enumii, enumiii, enumiv
\arabic{enumi}
\alph{enumi}
\roman{enumi}
\Alph{enumi}
% リセット
\renewcommand\theenumi{\roman{enumi}}
\renewcommand\labelenumi{\theenumi}
% ページ番号もカウンター
\thepage % 現在のページ番号
% 自分のカウンターを定義
\newcounter{mycnt}
\setcounter{mycnt}{0}
\renewcommand\themycnt{\arabic{mycnt}}
\stepcounter{mycnt}\themycnt
\addtocounter{mycnt}{-1}
% amsmath
\usepackage{amsmath}
\numberwithin{equation}{section}
% カスタムリスト環境
% 一般リスト
\begin{list} % \list{ラベル}{設定コマンド}
\item
\end{list}
\newcounter{mylist}
\begin{list}{\#\themylist}{\usecounter{mylist}}
\item 中文
\item English
\end{list}
% または enumitem パッケージを使用
\usepackage{enumitem}
\begin{enumerate}[itemsep=0pt,parset=0pt,label=(\arabic*)] % 設定
\item 中文
\item English
\end{enumerate}
定理
\usepackage{theorem}
% 定理
\newtheorm{thm}{定理} % 「定理」は定理のタイトル
\begin{thm}
一つの定理
\end{thm}
\begin{thm}[勾股定理]
名前のある定理
\end{thm}
% lemma
\newtheorm{lemma}{引理}[chapter] % 章ごと
\begin{lemma}
...
\end{lemma}
% proposition
\newtheorm{prop}[thm]{命題} % thm は番号の方法
\begin{prop}
...
\end{prop}
% 定理のフォーマットを設定
\usepackage{theorem}
\theoremstyle{changebreak}
\theoremheaderfont{\sffamily\bfseries}
\theorembodyfont{\normalfont}
\newtheorem{definition}{定義}[chapter]
\theoremstyle
% またはより強力な `ntheorem` パッケージ、または `amsthm`
\usepackage{amsthm}
\renewcommand\proofname{証明}
\renewcommand\qedsymbol{\ensuremath{\Box}} % 証明完了(Q.E.D)
Verbatim
% verbatim:\ver<シンボル><抄録内容><シンボル>
\verb"\LaTeX"
\verb!\LaTeX!
\verb*!1 2 3 4! % *(スペースを表示)
% 環境を使用
\begin{verbatim}
#!usr/bin/env perl
...
\end{verbatim}
\begin{verbatim*}
...
\end{verbatim*}
% パッケージを使用
\usepackage{fancyvrb}
\SaveVerb{myverb}|shit[({=-+[/})|
\fbox{セット中 \UseVerb{myverb}}
% プログラムハイライト
\usepackage{listings}
\begin{lstlisting}[language=C]
...
\end{lstlisting}
\lstset{ % 全体設定
column=flexible % lstset{flexiblecolumns} と等しい
commentstyle=\rmfamily\itshape}
tabbing
\begin{tabbing}
フォーマット\hspace{3em} \= 作者 \kill % be killed、この行は表示されません
Plain \TeX \> 高德纳 \\ % \\ で改行
\LaTeX \> Leslie Lamport % 最後の行は改行不要
\end{tabbing}
脚注
\footnote{これは脚注です}
\footnote[1]{これは別の脚注です} % 脚注記号は thefootnote
\begin{minipage}{8em} % 対応するのは thempfootnote
これは小さなページ環境\footnote{脚注。}の中の脚注です
\end{minipage}
\renewcommand\thefootnote{\fnsymbol{footnote}}
\renewcommand\thefootnote{\textcircled{\arabic{footnote}}}
% より良い方法
\usepackage{pifont}
\renewcommand\thefootnote{\ding{\numexpr171+\value{footnote}}} % 陽文付きの囲まれた数字は171から始まります
% footnotemark footnotetext
\begin{tabular}{r|r} % 右揃え、右揃え
自変数 & 因変数\footnotemark \\ \hline % 脚注マークを追加
$x$ & $y$
\end{tabular}
\footnotetext{$y=x^2$。} % 脚注内容を追加
% マージン注釈 \marginpar
マージン注釈のあるテキスト\marginpar[\hfill 左 $\rightarrow$]{\leftarrow 右}
\reversemarginpar
\normalmarginpar
\marginparwidth % 幅
\marginparsep % 間隔、setlength で設定
スペース
\vspace{<長さ>}
\vfill % つまり \vspace{\fill}
% スキップ
\smallskip % smallskipmount
\medskip % medskipmount
\bigskip % bigskipmount
% ボトム
\raggedbottom
\flushbottom
\parbox[<位置>][<高さ>][<内容位置>]{<Width>}{<Content>}
前沿\parbox{2em}{不搭后语}。 % 面白い例
\parbox[t]{2em}{Content} % 上部にバウンド
\parbox[b]{2em}{Content} % 下部にバウンド
\parbox[c]{2em}{Content} % 中央揃え
\parbox[s]{2em}{Content} % ストレッチ
![前言不搭后语][001]
% ルール
\rule[<高さ>]{<Width>}{<Height}
\rule{1pt}{1em}Middle\rule{1p}
\rule[-0.1em]{1em}{1em} Q.E.D. として使用可能
% 構造
\fbox{\strut---}\qquad
タイトルページ
\title{雑談勾股定理\thanks{某某に対する大きな支援に感謝}} % 特殊な感謝の脚注を生成
\author{張三は左に\\三明堂 \and 李四は右に\\四合院}
\data\today % 省略可能
% フォーマットを設定
![CTEXOptions][002]
層次 | 名称 | コマンド | 説明 |
---|---|---|---|
-1 | part | \part | オプションの最高層 |
0 | chapter | \chapter | report, book の最高層 |
1 | section | \section | article の最高層 |
2 | subsection | \subsection | |
3 | subsubsubsection | \subsubsubsection | report, book |
4 | paragraph | \paragraph | 番号なし、目次を生成しない |
5 | subparagraph | \subparagraph 番号なし、目次を生成しない |
% 全書
\frontmatter % 书の前段
\mainmatter % 书の正文、ページ番号を再計算
\backmatter % 书の後段、番号なし
\clearpage
\include{lang-natural} % lang-natural.tex 文書を引き入れる
\include{a-complex-table}
\includeonly{lang-natural} % preamble で特定の章のみ引き入れる設定が可能
一つの例
% main.tex
\documentclass{ctexart}
\input{preamble} % 複雑な導言区
\begin{document}
...
\end{document}
% a-complex-table.tex
...
\endinput % 出力を停止
これは複雑な表で、main.tex から分離するのが最適です。
主文書を直接コンパイルしてください:
xelatex main.tex
CTeX の設定
% \CTEXsetup[<key>=<value>,etc.]{<オブジェクトタイプ>}
% オブジェクトタイプ:part, chapter, section, subsection, subsubsection, paragraph, subparagraph
\CTEXsetup[name={第,节}]{section} % 「第 1 节」のように変わります
\CTEXsetup[number={\chinese{section}}]{section} % 「第一节」のように変わります
\CTEXsetup[format={\raggedright\bfseries}]{section}
% nameformat
% numberformat
% titleformat
% aftername、章名と後のタイトルの間の内容
\CEXsetup[aftername={\\vspace{2em}}]{part}
% beforeskip, afterskip 前後のスキップ距離
% indent 章タイトルのインデント長さ
% フォーマットを追加
\CTEXsetup[titleformat+={\fansong}]{subsection} % 「=」と「+=」の違いを考える
\documentclass[a4paper,titlepage]{article} % タイトルを単独のページに
% a4paper, a5paper, b5paper, letterpaper, leagalpaper, executivepaper
% landscape 横向き用紙
% oneside, twoside
% 10pt, 11pt, 12pt
% onecolumn, twocolumn
% titlepage, notitlepage
% openany, openright(各章は奇数ページから始まる)
% leqno 数式左側の番号
% fleqn 数式左揃え、固定長(デフォルトは中央揃え)
% draft コンパイルされた pdf にヒントが表示される
% final (デフォルト値)
% openbib
CTEXart, CTEXrep, CTEXbook#
article
, report
, book
vs. ctexart
, ctexrep
, ctexbook
% ctex.sty, ctexcap.sty
ctexcap.sty
\documentclass{ltxdoc}
\usepackage{ctexcap}
\zihao{5}
\begin{document}
...
\end{document}
ctex.sty
\documentclass{moderncv} % 履歴書
\usepackage{ctex}
\zihao{-4}
\begin{document}
...
\end{document}
UTF-8 について
\XeTeXinputencoding "GBK" % XeTeX は非 UTF-8 エンコーディング文書を処理
% ctexutf8, ctexcaputf8 % documentclass[UTF-8]{ctexart} のように
% ctexartutf8, ctexreputf8, ctexbookutf8
Geometry
\paperwidth \hoffset
\paperheight \voffset
\topmargin
\headhight \headsep
\textheight \textwidth
\marginparsep % マージン注釈の sep
\marginparwidth
\footskip % なぜ footsep ではないのか?最後の行は変化するため、脚注はそのページの最後の行のすぐ後に続くため、スキップで分ける
% 幾何学を設定する方法 1
\usepackage[a4paper,left=3cm,right=3cm]{geometry}
% 幾何学を設定する方法 2
\usepackage{geometry}
\geometry{a4paper,left=3cm,right=3cm} % 右マージン
![幾何学の設定][003]
ページスタイル
\pagenumbering{roman}
% ページスタイル:
% empty:ヘッダー、フットノートなし
% plain:ヘッダーなし、フットノートは中央ページ番号
% headings:フットノートなし、ヘッダーは章名
% myheadings:フットノートなし、ヘッダーはページ数とカスタム内容
\pagestyle{<スタイル>} % 全体を設定
\thispagestyle{<スタイル>} % このページを設定
\documentclass{article}
\pagetsyle{headings}
% 大幅画像、現在のページは plain スタイルを使用
\begin{figure}[p]
\thispagestyle{plain}
...
\end{figure}
![ページスタイル][004]
fancyhdr
![Fancyhdr][005]
\lhead{<内容>} \chead{<c>} \rhead{<c>}
\lfoot{<内容>} \cfoot{<c>} \rfoot{<c>}
\fancyhead[<位置>]{<c>} % E/O + L/C/R, 偶数/奇数ページ番号
\fancyfoot[<位置>]{<c>} % E/O + L/C/R, 左/中央/右
\fancyhf[<位置>]{<c>} % H/F + E/O + L/C/R
% 例:
\documentclass[twoside]{ctexrep}
\usepackage{fancyhdr}
\pagestyle{fancy}
\cfoot{\thepage}
\fancyhead[CO]{張三}
\fancyhead[CE]{論言語}
\fancyfoot[RO,LE]{$\heartsuit$}
% \leftmark \rightmark は通常「章」「節」名
\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[C]{\thepage}
% スタイルを再定義
\renewcommand\headrulewidth{0.6pt} % デフォルト:0.4pt
\renewcommand\footrulewidth{0.6pt} % デフォルト:0.4pt
\fancypagestyle{plain}{%
\fancyhf{}
\cfoot{--\textit{\thepage}--} % ページ番号の形
\renewcommand\headrulewidth{0pt}
\renewcommand\footrulewidth{0pt}
}
% カラム
\documentclass[twocolumn]{article}
% \onecolumn
% \twocolumn
マクロ
- コマンド
\boldface{boldfaced text}
- 環境
\begin{tabular} ... \end{tabular}
% \newcommand<コマンド>[<パラメータ数>][<最初のパラメータのデフォルト値>]{具体的な定義}
\newcommand\PRC{People's Republic of \emph{China}}
\newcommand\drives[2]{#1 drives #2} % \loves{Driver}{car} === driver drives car
\newcommand\does[3][drives]{#2 #1 #3} % \does{driver}{car} ===> driver drives car, \does{like}{I}{fish} ===> I like fish
% renewcommand は \newcommand に似ていますが、再定義に使用
\renewcommand\abstractname{内容概要}
% providecommand は簡単なバージョンを提供し、他のバージョンがあればこのバージョンが置き換えられます
\providecommand\url[1]{\texttt{#1}} % 簡単な URL 実装、ただしこのコマンドがないことを心配しています(しかし、恐らくこのコマンドは存在するので、単に「簡素な」実装を提供します)
% または両者が組み合わさることがあります
\providecommand \renewcommand % 以前に定義されているかどうかに関わらず、新しいコマンドを定義します
複雑な例
\newcommand\Emph[1]{\emph{#1}}
\newcommand\setEmph[1]{%
\renewcommand\setEmph[1]{%
#1{##1}}}
TODO:この部分は自分で実践してください
% コマンド vs. 環境
{\quote ... \endquote}
\begin{quote}
...
\end{quote}
\newenvironment{<環境名>}[<パラメータ数>][<最初のパラメータのデフォルト値>]{環境前の定義}{<環境後の定義>}
\renewenvironment{<環境名>}[<パラメータ数>][<最初のパラメータのデフォルト値>]{環境前の定義}{<環境後の定義>}
\newenvironment{myabstract}[1][概要] %
{\small
\begin{center}\bfseries #1\end{center}
\begin{quotation}} % 環境前の定義
{\end{quotation}} % 環境後の定義(ここでは環境パラメータを使用できません)
劉海洋のまとめ:
コマンドと環境を定義することは、LaTeX フォーマットのカスタマイズ、内容とフォーマットの分離を目指すための強力なツールです。カスタムコマンドと環境を使用して、フォント、フォントサイズ、インデント、整列、間隔などのさまざまな詳細をラップし、意味のある名前を付けることで、文書構造を明確にし、コードを整然とし、保守しやすくすることができます。マクロ定義機能を使用する際は、さまざまな既存のコマンド、環境、変数などの機能を総合的に活用する必要があります。実際、前述の長さ変数やボックス、フォントサイズなどの内容は、主に本文中には直接表示されませんが、さまざまな構造を実現するマクロ定義の中で使用されます。
自動化ツール#
\tableofcontents % 目次は少なくとも二回コンパイルしないと表示されません
\listoffigures
\listoftables
![目次][006]