tcolorboxパッケージを用いたカラフルな定理環境
目標
本記事では, LaTeXパッケージの一つであるtcolorboxを用いた以下の定理環境の解説を行う.
ソースコードは以下の通りである.
ただし筆者はlualatexを用いているのでドキュメントクラスにltjsarticle
を指定しているが,
別に他の環境でも問題なく動くであろうことは注意しておく.
\documentclass{ltjsarticle} \usepackage{tcolorbox} \tcbuselibrary{theorems,skins,breakable} \tcbset{ thmstyle/.style={ colframe=blue!50!black, colback=blue!50!black!2!white, colbacktitle=blue!50!black, boxrule=0pt, left*=1\zw, right*=1\zw, sharp corners, before skip=1\zw, after skip=1\zw, before upper={\setlength{\parindent}{1\zw}}, breakable, }, defstyle/.style={ colframe=red!50!black, colback=red!50!black!2!white, colbacktitle=red!50!black, boxrule=0pt, left*=1\zw, right*=1\zw, sharp corners, before skip=1\zw, after skip=1\zw, before upper={\setlength{\parindent}{1\zw}}, breakable, } } \newtcbtheorem{thm}{Theorem}{thmstyle}{thm} \newtcbtheorem{defi}{Definition}{defstyle}{defi} \begin{document} \begin{thm}{やば定理}{sugoiteiri} 以下のやばい等式が成り立つ: \begin{align*} e^{i\pi+1}=0. \end{align*} \end{thm} \begin{defi}{エモ定義}{sugoiteigi} 以下のようにエモい定義をする: \begin{align*} 2:=1+1. \end{align*} \end{defi} \end{document}
さらに自分なりに改変したい場合は, 「tcolorbox 定理環境」等でググっていただければ
本記事よりも丁寧で分かりやすい解説がいくつも出てくるはずである.
または, ターミナル上でtexdoc tcolorbox
と実行すればtcolorboxパッケージの公式ドキュメントが見れるので, そちらも参照していただければ幸いである.
一番簡単な定理環境の書き方
まずは一番簡単な定理環境の書き方を述べる. 一度, 以下のソースコードをタイプセットしてみる.
\documentclass{ltjsarticle} \usepackage{tcolorbox} \tcbuselibrary{theorems} \newtcbtheorem{mythm}{My Theorem}{}{thm} \begin{document} \begin{mythm}{すごい定理}{ラベル名} これはすごい定理である. \end{mythm} Theorem \ref{thm:ラベル名}より, すごいことが分かる. \end{document}
すると, 以下のような出力が得られるはずである.
さて, 上に載せたコードを順に説明する.
\usepackage{tcolorbox} \tcbuselibrary{theorems}
一行目は言わずもがな, tcolorboxパッケージの読み込みである.
tcolorboxは名前の通り, 色付きのboxを出力するパッケージである.
そのため, 定理環境を作るためには新たなライブラリを読み込む必要がある.
それを二行目で行っている.
theorems
以外のライブラリには例えば次のようなものがある.
ページ跨ぎを許す
breakble
.定理環境の囲みの見た目を変える
skins
.
\newtcbtheorem{mythm}{My Theorem}{}{thm}
定理環境の設定は, \newtcbtheorem{<name>}{<display name>}{<options>}{<prefix>}
という形で記述する.
<name>
には定理環境の名前そのものを指定する.
したがって上ではmythm
と指定しているので, 本文中では\begin{mythm} \end{mythm}
のように書くことになる.
<display name>
には表示名を指定する.
和文ならば定理
, 欧文ならTheorem
等が妥当だろうか.
<options>
には様々なオプションを指定する.
上のソースコードを見てもらえば分かる通り, 空白にすれば必要最低限の定理環境が得られる.
オプションはかなりの種類があるので, 本記事では紹介しきれない. 気になる方は公式ドキュメントを見ていただきたい.
<prefix>
には, prefix(接頭辞)を指定する.
例えばprefixをthm
と, ある定理のラベルをhoge
と指定すれば,
その定理(番号)は\ref{thm:hoge}
と記述することで引用できる.
\begin{mythm}{定理名}{ラベル名} これはすごい定理である. \end{mythm}
実際の定理環境は\begin{<name>}{<display name>}{<options>}{<label name>} \end{<name>}
という形で記述する.
オプションテンプレート
これで綺麗な定理環境が出力できるようになった.
とすれば, 定理だけでなく, 定義・例・補題・命題・系・注意・予想, といった環境を作りたい.
しかし, それら一つ一つに対して\newtcbtheorem{defi}{My Def}{<大量のオプション>}{defi}
と書いていくのは,
プリアンブルが汚くなったり, 見づらくなったりといった問題点がある.
この問題点を解決するために, オプションテンプレートを作ることにする.
オプションテンプレートの作り方は簡単で, プリアンブルに\tcbset{<options>}
と書くだけである. 例えば次のソースコードをタイプセットすれば, 確かに定理環境が変化しているのが分かるだろう.
\documentclass{ltjsarticle} \usepackage{tcolorbox} \tcbuselibrary{theorems} \tcbset{ colback=green!5, colframe=green!35!black, } \newtcbtheorem{mythm}{Theorem}{}{thm} \begin{document} \begin{mythm}{すごい定理}{ラベル名} これはすごい定理である. \end{mythm} Theorem \ref{thm:ラベル名}より, すごいことが分かる. \end{document}
複数のオプションテンプレート
定理のboxの色と定義のboxの色は異なるものにした方が見やすい.
しかし先ほどの\tcbset{<options>}
は, 全てのtcolorboxの設定を統一してしまうという難点がある.
したがって, オプションテンプレートを複数設定し, 定理環境ごとにどのオプションテンプレートを用いるか指定する必要がある.
それは, 次のようにして達成される.
\documentclass{ltjsarticle} \usepackage{tcolorbox} \tcbuselibrary{theorems} \tcbset{ thmstyle/.style={ colframe=blue!50!black, colback=blue!50!black!2!white, colbacktitle=blue!50!black, }, defstyle/.style={ colframe=red!50!black, colback=red!50!black!2!white, colbacktitle=red!50!black, } } \newtcbtheorem{mythm}{Theorem}{thmstyle}{thm} \newtcbtheorem{mydefi}{Definition}{defstyle}{defi} \begin{document} \begin{mythm}{すごい定理}{定理のラベル名} これはすごい定理だ. \end{mythm} \begin{mydefi}{すごい定義}{定義のラベル名} びっくりする定義. \end{mydefi} \end{document}
定理のオプションテンプレート名をthmstyle
として,
style
変数にオプションをつらつら書いていけばよい.
定義の方も全く同様である.
そして\newtcbtheorem{<name>}{<display name>}{<options>}{<prefix>}
の<options>
の部分に,
適用したいオプションテンプレート名を指定すればよい.
オプションについて
colframe, colback, colbacktitle
colorboxの枠, 中身の背景, タイトル部分の背景, の色の指定. 色に関する説明はここでは省略する.
colframe=blue!50!black, colback=blue!50!black!2!white, colbacktitle=blue!50!black,
↓
boxrule
colorboxの枠の太さの変更.
boxrule=0pt,
↓
left, right
それぞれ, 本文の左側と右側のスペースの調整(インデント幅ではない).
left*=1\zw, right*=1\zw,
↓
sharp corners
↓
before skip, after skip
colorboxの前後の文章との間に空白を入れる. 以下の例は分かりやすくするために, あえて数値を大きく設定している.
before skip=10\zw, after skip=10\zw,
↓
before upper
定理環境の本文部分だけの設定(定理名の部分には影響を与えない). (正確には, 一般のcolor boxのupper部分とlower部分に対して, upper部分の前に配置される設定であるが, ここでは詳細は省略する.) ここでは本文の最初に1\zwのインデントを与えるという設定をしている. 以下の例でも分かりやすくするために, あえて数値を大きく設定している.
before upper={\setlength{\parindent}{5\zw}},
↓
breakble
定理環境中にページを跨ぐことを許す設定.
Visual Studio CodeにおけるLaTeX執筆環境の構築及びテンプレート
Visual Studio CodeにおけるLaTeX執筆環境の構築及びテンプレートについて書くぞという強い意志がここにはある.
(2022/12/12 追記) 環境構築に関して書く余裕は未だに無いが, とりあえずsetting.jsonの中身だけコピペしておきます.
{ // --------- General Setteing --------- // ミニマップを表示しない "editor.minimap.enabled": false, // 予測変換等を表示しない "editor.quickSuggestions": { "other": "off", "comments": "off", "strings": "off" }, "editor.suggest.showClasses": false, "editor.suggest.showColors": false, "editor.suggest.showConstants": false, "editor.suggest.showConstructors": false, "editor.suggest.showCustomcolors": false, "editor.suggest.showDeprecated": false, "editor.suggest.showEnumMembers": false, "editor.suggest.showEnums": false, "editor.suggest.showEvents": false, "editor.suggest.showFields": false, "editor.suggest.showFiles": false, "editor.suggest.showFolders": false, "editor.suggest.showFunctions": false, "editor.suggest.showIcons": false, "editor.suggest.showInlineDetails": false, "editor.suggest.showInterfaces": false, "editor.suggest.showIssues": false, "editor.suggest.showKeywords": false, "editor.suggest.showMethods": false, "editor.suggest.showModules": false, "editor.suggest.showOperators": false, "editor.suggest.showProperties": false, "editor.suggest.showReferences": false, "editor.suggest.showSnippets": false, "editor.suggest.showStructs": false, "editor.suggest.showTypeParameters": false, "editor.suggest.showUnits": false, "editor.suggest.showUsers": false, "editor.suggest.showValues": false, "editor.suggest.showVariables": false, "editor.suggest.showWords": false, // ---------- LaTeX Workshop ---------- // ビルドのレシピ "latex-workshop.latex.recipes": [ { "name": "latexmk", "tools": [ "latexmk" ] }, ], // ビルドのレシピに使われるパーツ "latex-workshop.latex.tools": [ { "name": "latexmk", "command": "latexmk", "args": [ "%DOCFILE%" // icloud上のtexファイルをタイプセットするため, %DOC% -> %DOCFILE% とする. https://github.com/James-Yu/LaTeX-Workshop/issues/1773 ], }, ], // 削除対象とするファイルの拡張子 "latex-workshop.latex.clean.fileTypes": [ "*.aux", "*.bbl", "*.blg", "*.idx", "*.ind", "*.lof", "*.lot", "*.out", "*.toc", "*.acn", "*.acr", "*.alg", "*.glg", "*.glo", "*.gls", "*.ist", "*.fls", "*.log", "*.fdb_latexmk", "*.snm", "*.nav", "*.dvi", ], // 補助ファイルを削除. 削除するファイルは「OutDir」に入っている. "latex-workshop.latex.autoClean.run": "onBuilt", // 使用パッケージのコマンドや環境の補完を有効にする "latex-workshop.intellisense.package.enabled": true, // タイプセットに失敗した場合, エラーと注意のポップアップを表示しない "latex-workshop.message.error.show": false, "latex-workshop.message.warning.show": false, // hover(カーソルを合わせたときに表示される補助ウィンドウ)を表示しない "latex-workshop.hover.preview.enabled": false, "latex-workshop.hover.citation.enabled": false, "latex-workshop.hover.command.enabled": false, "latex-workshop.hover.preview.newcommand.parseTeXFile.enabled": false, "latex-workshop.hover.ref.enabled": false, }
latexmkテンプレートと簡単な解説
本記事は, Mac OSを対象に書いています.
latexmkを使う理由
LaTeXで何かを執筆しているときに
- ラベルをpdfに反映させるためにタイプセットを何回かするのめんどくさい
- 参考文献を引用する際にpLaTeXとbibtexを何回かタイプセットするのがめんどくさい
- texファイルとpdfファイルだけしか必要としないのに, auxファイルとかdviファイルとかいらない.
と思ったことが一度はあるんじゃないだろうか.
そんなときに役立つのがlatexmk(ラテフメイク)というソフトである.
latexmkを使用すれば, 一度のタイプセットでpLaTeXやbibtex等, 正しい出力がなされるまで自動的に複数回タイプセットしてくれる.
また, オプションの設定を行うことで, 不必要な補助ファイルを一気に削除してくれる.
これは使ってみるしかない, ということで私が使用しているlatexmkの設定と, 簡単な解説をしたいと思う.
.latexmkrc
の設定
まずはテキストエディットを開き, 新規書類を作成する.
中身は一旦何も書かず, ファイル名を.latexmkrc
と変更し, 自分のユーザー名のディレクトリに保存する(書類とかムービーとかのフォルダがあるとこ).
ただし, 拡張子が非表示になっていて実は.latexmkrc.txt
のようなファイル名になっている, なんてことがあれば, .txt
の部分を消しておく.
次にファインダーを開き, ユーザーのディレクトリに移動する.
そしてShift
+Command
+.
を押すことで, 隠しフォルダを表示させる. (もう一度押せば非表示になる)
先ほど作成した.latexmkrc
ファイルがあると思うので, ダブルクリックして開く.
そこに, latexmkの設定を自由に記述して保存すれば設定完了.
私は以下のように設定している.
#!/usr/bin/env perl # file .latexmkrc # author Nekodesu # created_at 2022.06.11 # modified_at 2022.08.28 $latex = 'platex -synctex=1 -interaction=nonstopmode -file-line-error %O %S'; $bibtex = 'pbibtex -kanji=utf8 %O %S'; $dvipdf = 'dvipdfmx %O -o %D %S'; $pdf_mode = 3; $max_repeat = 5;
$latex
変数
$latex = 'platex -synctex=1 -interaction=nonstopmode -file-line-error %O %S';
まずは拡張子tex
のファイルから拡張子dvi
のファイルを作成するための処理系の設定を行う.
基本的に私はpLaTeXを使用するので
$latex = 'platex %O %S';
と書き込む.
ここで, %O
というのは実行時オプション, %S
というのは入力ファイル名を表す.
つまり, 何かpLaTeXで処理を行う際に付けるオプションが%O
に, 実行するファイル名が%S
に代入される.
しかし毎回付けるオプションもあるので, それは固定しておくべきである.
それが-synctex=1 -interaction=nonstopmode -file-line-error
の部分である.
synctex
: 1に設定するとSyncTeXが有効になり, 適切なpdf viewerを用いることでpdfの文章から該当するソースコードに飛べたりする.interaction=nonstopmode
: タイプセット中にエラーが起きても、ユーザーにどう処理するかの指示を求めずコンパイルを続行する.file-line-error
: texファイルの何行目でエラーが発生したかを表示.
$bibtex
変数
$bibtex = 'pbibtex -kanji=utf8 %O %S';
bibtexを実行する際の設定.
日本語の参考文献も引用することがあるので, 処理系はpbibtexにする.
また, オプションkanji=utf8
を設定しておく.
$dvipdf
変数
$dvipdf = 'dvipdfmx %O -o %D %S';
拡張子.dvi
のファイルから拡張子.pdf
のファイルを作成するためのコマンドの設定.
標準なものであるdvipdfmxに設定をする. (あまり分かっていない)
$pdf_mode
変数
$pdf_mode = 3;
使用するコマンドによってpdfの出力形式を合わせる設定.
- 0: pdf化しない
- 1: $pdflatex変数で指定されたコマンドを使う
- 2: $ps2pdf変数で指定されたコマンドを使う
- 3: $dvipdf変数で指定されたコマンドを使って, dviファイルからpdfを作成する
- 4: $lualatexでpdfを作成する
- 5: $xelatexでpdfを作成する
先ほどの$dvipdf`変数で設定したコマンドを使いたいので, ここでは3に設定する.
$max_repeat
変数
$max_repeat = 5;
最大タイプセット回数を指定. 警告が出なくなるまで無限にタイプセットを繰り返される可能性を防ぐ.
latexmkの使い方
1. 適当にtest.tex
というファイルを作成する. (適当に中身を書いていてもよい)
2. ターミナルを開き, test.tex
があるディレクトリ上で以下を実行する.
latexmk test.tex
3. そのディレクトリ上でtest.dvi
, test.aux
, test.pdf
等のファイルが作成される.
また, オプションを付けて実行することで様々な機能を使用することができる. 例えば
latexmk -c test.tex
と実行すると, test.dvi
やtest.aux
等の中間生成ファイルを削除してくれる. しかし
- 一度のタイプセットで済むのはいいが, ターミナル上で実行するのがめんどくさい. だったらTeXShop等のエディタで複数回タイプセットする方が視覚的にも分かりやすくていい
なんて難点が浮かび上がる.
この点は, 別の記事で書く予定である, Visual Studio CodeによるTeX執筆環境の構築により回避する.
参考文献
LaTeXテンプレートと簡単な解説
普段, 勉強ノートやレポート等に使っているLaTeXテンプレートをまとめておきます.
大幅にテンプレートを構成し直しています. (最終更新 2022/12/11)
テンプレートを見る
\documentclass[10pt,titlepage,dvipdfmx]{jsarticle} %------------------------------------------------ % 文書クラス. %------------------------------------------------ \usepackage{algorithm,algpseudocode} % 擬似コード \usepackage{amssymb,amsmath} % 数学記号 \usepackage{amsthm} % 定理環境 \usepackage{bm} % 太文字 \usepackage{clock} % 時計 \usepackage{color} % 文字色の追加 \usepackage[OT2,T1]{fontenc} % キリル文字用 \usepackage{framed} % leftbar環境用 \usepackage{graphicx} % 図の挿入 \usepackage{geometry} % レイアウト設定 \usepackage{indentfirst} % 段落初めをインデントする \usepackage{listings,jvlisting} % コード \usepackage{mathrsfs} % 花文字 \usepackage{mathtools} % showonlyrefs等の便利ツール \usepackage[leftmarker]{mindflow} % アイデアを書く環境 \usepackage{tcolorbox} % 綺麗な定理環境 \usepackage{tikz} % 図の作成 %------------------------------------------------ % パッケージ. %------------------------------------------------ \geometry{margin=15truemm} %------------------------------------------------ % レイアウト設定. %------------------------------------------------ \allowdisplaybreaks[4] \mathtoolsset{showonlyrefs=true} %------------------------------------------------ % 数式に関する設定. % allowdisplaybreaks: align環境において式の途中で改ページを許す. (許容度 1~4) % showonlyrefs: 引用するときのみ式番号を表示. %------------------------------------------------ \tcbuselibrary{breakable,skins,theorems} \definecolor{burgundy}{rgb}{0.5, 0.0, 0.13} \definecolor{charcoal}{rgb}{0.21, 0.27, 0.31} \tcbset{mytheo1/.style={ fonttitle=\gtfamily\sffamily\bfseries\upshape, enhanced, colframe=burgundy, colback=burgundy!2!white, colbacktitle=burgundy, boxrule=0pt, borderline south={2pt}{-2pt}{burgundy}, left*=1zw, right*=1zw, theorem style=standard, breakable,sharp corners, before skip=8pt, after skip=10pt, before upper={\setlength{\parindent}{1zw}}, before lower={\setlength{\parindent}{1zw}} }} \tcbset{mytheo2/.style={ fonttitle=\gtfamily\sffamily\bfseries\upshape, enhanced, colframe=blue!50!black, colback=blue!50!black!2!white, colbacktitle=blue!50!black, boxrule=0pt, borderline south={2pt}{-2pt}{blue!50!black}, left*=1zw, right*=1zw, theorem style=standard, breakable,sharp corners, before skip=8pt, after skip=10pt, before upper={\setlength{\parindent}{1zw}}, before lower={\setlength{\parindent}{1zw}} }} \tcbset{mytheo3/.style={ fonttitle=\gtfamily\sffamily\bfseries\upshape, enhanced, colframe=charcoal, colback=charcoal!2!white, colbacktitle=charcoal, boxrule=0pt, borderline south={2pt}{-2pt}{charcoal}, left*=1zw, right*=1zw, theorem style=standard, breakable,sharp corners, before skip=8pt, after skip=10pt, before upper={\setlength{\parindent}{1zw}}, before lower={\setlength{\parindent}{1zw}} }} \newtcbtheorem[number within=section]{thm}{Theorem}{mytheo1}{thm} % Theorem \newtcbtheorem[use counter from=thm]{prop}{Proposition}{mytheo1}{prop} % Proposition \newtcbtheorem[use counter from=thm]{cor}{Corollary}{mytheo1}{cor} % Corollary \newtcbtheorem[use counter from=thm]{defi}{Definition}{mytheo2}{defi} % Definition \newtcbtheorem[use counter from=thm]{lem}{Lemma}{mytheo1}{lem} % Lemma \newtcbtheorem[use counter from=thm]{ex}{Example}{mytheo3}{ex} % Example \newtcbtheorem[use counter from=thm]{rem}{Remark}{mytheo3}{rem} % Remark %------------------------------------------------ % 定理環境. %------------------------------------------------ \makeatletter \newcommand{\MyAlphabet}[1]{\@tfor\Ch@r:=#1\do{ \expandafter\edef\csname bb\Ch@r\endcsname{\noexpand\mathbb{\Ch@r}} \expandafter\edef\csname cal\Ch@r\endcsname{\noexpand\mathcal{\Ch@r}} \expandafter\edef\csname frak\Ch@r\endcsname{\noexpand\mathfrak{\Ch@r}} \expandafter\edef\csname scr\Ch@r\endcsname{\noexpand\mathscr{\Ch@r}} }} \makeatother \MyAlphabet{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz} \let\Re\relax \DeclareMathOperator{\Re}{Re} \let\Im\relax \DeclareMathOperator{\Im}{Im} \let\epsilon\relax \DeclareMathOperator{\epsilon}{\varepsilon} \makeatletter \newcommand{\MyMathOperators}[1]{\@for\op:=#1\do{ \expandafter\edef\csname\op\endcsname{\noexpand\mathop{\noexpand\mathrm{\op}}\nolimits} }} \makeatother \MyMathOperators{% Ker,% Coker,% Hom,% End,% Aut,% id,% Gal,% ch,% ord,% Spec,% Specm,% Frac,% rank,% corank,% sgn,% alg,% Reg,% Sel,% Cl,% lcm,% gcd,% Ann,% alg,% } %------------------------------------------------ % 新しい数学演算子の定義. % 参考: % https://mathlandscape.com/declaremathoperator/ %------------------------------------------------ \renewcommand{\bar}[1]{\overline{#1}} \renewcommand{\tilde}[1]{\widetilde{#1}} \renewcommand{\hat}[1]{\widehat{#1}} \newcommand{\red}[1]{\textcolor{red}{#1}} % コメント用 \newcommand{\blue}[1]{\textcolor{blue}{#1}} % コメント用 \newenvironment{btl}{\begin{leftbar}\color{gray}}{\color{black}\end{leftbar}} % 行間(between the lines)埋め \let\|\relax \newcommand{\|}{\verb|} % 入力した文字をそのまま出力 %------------------------------------------------ % 新しい関数や補助関数の定義. %------------------------------------------------ \renewcommand{\mindflowTextFont}{\normalfont\footnotesize\sffamily\itshape} % mindflow環境のテキストフォント変更 \renewcommand{\mindflowNumFont}{\normalfont\footnotesize\sffamily} % mindflow環境の数字フォント変更 \renewcommand{\mindflowLeft}{\hspace{1em}\(\succ\)} % mindflow環境の左側の設定 \renewcommand{\mindflowRight}{\(\prec\)} % mindflow環境の右側の設定 \setlength{\mindflowLineHeight}{1pt} % mindflow環境の行間調整 %------------------------------------------------ % mindflow環境. %------------------------------------------------ \DeclarePairedDelimiter{\skakko}{\lparen}{\rparen} % 括弧( ) \DeclarePairedDelimiter{\mkakko}{\lbrace}{\rbrace} % 括弧{ } \DeclarePairedDelimiter{\lkakko}{\lbrack}{\rbrack} % 括弧[ ] \DeclarePairedDelimiter{\gkakko}{\langle}{\rangle} % 括弧< > \DeclarePairedDelimiter{\abs}{\lvert}{\rvert} % 絶対値| | \DeclarePairedDelimiterX{\set}[2]{\lbrace}{\rbrace}{#1\,\delimsize\vert\,#2} % 集合{ } %------------------------------------------------ % 括弧の大きさ等を自動的に調整. % 参考: % https://mathlandscape.com/declarepaireddelimiter/ %------------------------------------------------ \DeclareSymbolFont{cyrletters}{OT2}{wncyr}{m}{n} \DeclareMathSymbol{\Sha}{\mathalpha}{cyrletters}{"58} %------------------------------------------------ % Shaの出力. %------------------------------------------------ \renewcommand{\theenumi}{\roman{enumi}} % 箇条書きの第一階層の番号の付け方をi,ii,iii,...にする \renewcommand{\labelenumi}{(\theenumi)} \renewcommand{\theenumii}{\theenumi-\alph{enumii}} % 箇条書きの第二階層の番号の付け方をi-i,i-ii,i-iii,...にする \renewcommand{\labelenumii}{(\theenumii)} %------------------------------------------------ % enumerate環境の見出し変更. % 参考: % https://mathlandscape.com/latex-enum/ %------------------------------------------------ \makeatletter \renewcommand{\ALG@name}{Algorithm} \makeatother \algrenewcommand{\algorithmicrequire}{\textbf{Input:}} \algrenewcommand{\algorithmicensure}{\textbf{Output:}} \algrenewcommand{\algorithmicthen}{\textbf{:}} % if then -> if : \algrenewcommand{\algorithmicelse}{\textbf{else:}} % else -> else : \algrenewcommand{\algorithmicdo}{\textbf{:}} % while do -> while : \algnewcommand{\Continue}{\textbf{continue}} \algnewcommand{\Break}{\textbf{break}} %------------------------------------------------ % 擬似コード. %------------------------------------------------ \lstnewenvironment{sage}[1][]{ \lstset{ language=Python, basicstyle={\ttfamily}, % 全体のフォント identifierstyle={\small}, % キーワードでないもののフォント commentstyle={\smallitshape}, % コメントのフォント stringstyle={\small}, % 文字のフォント keywordstyle={\small\bfseries}, % ndkeywordstyle={\small}, % stringstyle={\small\ttfamily}, numberstyle={\scriptsize}, numbers=left, % 左に行番号を表示 stepnumber=1, % 数字がどれだけずつ増えるか numbersep=1zw, % 数字とコードの間のスペース xleftmargin=3zw, % 左側のスペース xrightmargin=0zw, % 右側のスペース breaklines=true, % 長いlineは折り返す frame={lines}, % 枠の種類 columns=[l]{fullflexible}, lineskip=-0.5ex }}{} %------------------------------------------------ % プログラムコード. %------------------------------------------------ \usepackage{hyperref} \usepackage{pxjahyper} \hypersetup{% colorlinks=true, % リンクのテキストに色を付ける linkcolor=blue, % \refによる標準リンクのテキストの色 citecolor=blue, % 参考文献リンクのテキストの色 urlcolor=blue, % URLリンクのテキストの色 } %------------------------------------------------ % 引用する際のリンク付け. % こいつは色々と悪さをするので, なるべく後半に読み込む. % pxjahyper: PDF機能のしおり機能の日本語文字化けを防ぐ (hyperrefの後に記述する) %------------------------------------------------ \def\MyMailAddress{メールアドレス} \title{タイトル} \author{氏名 \thanks{mail: \href{\MyMailAddress}{\texttt{\MyMailAddress}}}} \date{最終更新: \today \texthours 時 \textminutes 分 \clocktime} %------------------------------------------------ % タイトル設定. %------------------------------------------------
文書クラス
\documentclass[10pt,titlepage,dvipdfmx]{jsarticle}
プリアンブルに必ず一つだけ記述するもの. 書き方は
である. スタイルファイル名は例えば以下のような種類がある.
スタイルファイル名 | 備考 |
---|---|
jsarticle |
和文の論文執筆用. |
jsbook |
和文の本執筆用. |
article |
欧文の論文執筆用. |
book |
欧文の本執筆用. |
report |
欧文の報告書執筆用. 和文の報告書はない. |
beamer |
パワーポイントのようなスライドを作成できる. |
amsart |
米国数学会(American Mathmatical Society)が公開しているスタイルファイル. |
以下では, 特に使用することが多いであろうスタイルファイルjsarticle
で使用可能なオプションを, 主要なものをいくつかまとめる.
ただし, jsarticle
以外のスタイルファイルでも使用可能なオプションもあることに注意.
titlepage
: タイトルを独立したページを作成する.@pt
: 文字サイズ@ptにする. (@=10(defalut), 11, 12等)@paper
: 用紙サイズを@にする. (@=a4(default),a5, b4, b5)@column
: 文章を@段組にする. (@=one(default), two)@eqno
: 数式番号を@寄せ出力にする. (@=l(default), r)landscape
: 用紙の向きを横長にする.titlepage
: タイトルのみのページを作成する.slide
: 出力をスライド形式にする. beamerのシンプルバージョン.draft
,final
: draftを指定すると, 警告「overfull \hbox」が発生している箇所の右端に5ptの罫線を引く.
パッケージ
\usepackage{algorithm,algpseudocode} % 擬似コード \usepackage{amssymb,amsmath} % 数学記号 \usepackage{amsthm} % 定理環境 \usepackage{bm} % 太文字 \usepackage{clock} % 時計 \usepackage{color} % 文字色の追加 \usepackage[OT2,T1]{fontenc} % キリル文字用 \usepackage{framed} % leftbar環境用 \usepackage{graphicx} % 図の挿入 \usepackage{geometry} % レイアウト設定 \usepackage{indentfirst} % 段落初めをインデントする \usepackage{listings,jvlisting} % コード \usepackage{mathrsfs} % 花文字 \usepackage{mathtools} % showonlyrefs等の便利ツール \usepackage[leftmarker]{mindflow} % アイデアを書く環境 \usepackage{tcolorbox} % 綺麗な定理環境 \usepackage{tikz} % 図の作成
以下で記述しているマクロに必要となるパッケージ. (このようにパッケージだけ先に読み込むような書き方はあまり推奨されないと思います. 自己責任でお使いください.)
レイアウト設定
\geometry{margin=15truemm}
本テンプレートは私的な勉強ノート用なので, ページいっぱいに使えるように空白の指定をしている.
数式に関する設定
\allowdisplaybreaks[4]
複数行に渡る数式中の改ページを行うための設定. 通常, 何行にも渡る数式を書いていってページの最下部まで辿り着くと 勝手に新しいページの最上部からその数式を出力し始めてしまう. そもそも正式な文書ではそのような何行にも渡る数式を書くのは避けたいかもしれないが, 少なくとも個人のノートレベルでは構わないので, この設定をしておく. 数字「4」は, 改ページする許容度を表す数値であり, 整数値1~4を選択できる. 「1」とすれば, なるべく数式中の改ページをしないような設定になり, 「4」とすれば, 強制的に改ページをする設定となる.
\mathtoolsset{showonlyrefs=true}
個人的にこのテンプレートの中で一番便利だと思っているもの.
mathtools
パッケージに含まれている設定である.
参照したい数式は\begin{align}hoge\end{align}
と書いて,
参照したくない数式は, 数式番号を付けないように
\begin{align*}hoge\end{align*}
と書くのは, かなりめんどくさい.
そこで, showonlyrefs
を設定することで, 全ての数式環境を\begin{align}hoge\end{align}
と書けばよくなる.
「*
」が付いてないが, 出力には数式番号が振られなくなる.
しかしその数式にラベルを付けて参照することで, 数式番号が付けられる.
これを用いれば, 「やっぱりこの数式を参照しなくていいや」となった場合に「*
」をわざわざ外さなくてよい.
定理環境
\tcbuselibrary{breakable,skins,theorems} \definecolor{burgundy}{rgb}{0.5, 0.0, 0.13} \definecolor{charcoal}{rgb}{0.21, 0.27, 0.31} \tcbset{mytheo1/.style={ fonttitle=\gtfamily\sffamily\bfseries\upshape, enhanced, colframe=burgundy, colback=burgundy!2!white, colbacktitle=burgundy, boxrule=0pt, borderline south={2pt}{-2pt}{burgundy}, left*=1zw, right*=1zw, theorem style=standard, breakable,sharp corners, before skip=8pt, after skip=10pt, before upper={\setlength{\parindent}{1zw}}, before lower={\setlength{\parindent}{1zw}} }} \tcbset{mytheo2/.style={ fonttitle=\gtfamily\sffamily\bfseries\upshape, enhanced, colframe=blue!50!black, colback=blue!50!black!2!white, colbacktitle=blue!50!black, boxrule=0pt, borderline south={2pt}{-2pt}{blue!50!black}, left*=1zw, right*=1zw, theorem style=standard, breakable,sharp corners, before skip=8pt, after skip=10pt, before upper={\setlength{\parindent}{1zw}}, before lower={\setlength{\parindent}{1zw}} }} \tcbset{mytheo3/.style={ fonttitle=\gtfamily\sffamily\bfseries\upshape, enhanced, colframe=charcoal, colback=charcoal!2!white, colbacktitle=charcoal, boxrule=0pt, borderline south={2pt}{-2pt}{charcoal}, left*=1zw, right*=1zw, theorem style=standard, breakable,sharp corners, before skip=8pt, after skip=10pt, before upper={\setlength{\parindent}{1zw}}, before lower={\setlength{\parindent}{1zw}} }} \newtcbtheorem[number within=section]{thm}{Theorem}{mytheo1}{thm} % Theorem \newtcbtheorem[use counter from=thm]{prop}{Proposition}{mytheo1}{prop} % Proposition \newtcbtheorem[use counter from=thm]{cor}{Corollary}{mytheo1}{cor} % Corollary \newtcbtheorem[use counter from=thm]{defi}{Definition}{mytheo2}{defi} % Definition \newtcbtheorem[use counter from=thm]{lem}{Lemma}{mytheo1}{lem} % Lemma \newtcbtheorem[use counter from=thm]{ex}{Example}{mytheo3}{ex} % Example \newtcbtheorem[use counter from=thm]{rem}{Remark}{mytheo3}{rem} % Remark
tcolorbox
環境を用いた定理環境の設定.
かなり自由度が高い環境のため, 公式ドキュメントは非常に量が多く, 使いこなすには時間がかかる.
そのためここでは説明を省略する.
参考文献
数学演算子
\makeatletter \newcommand{\MyAlphabet}[1]{\@tfor\Ch@r:=#1\do{ \expandafter\edef\csname bb\Ch@r\endcsname{\noexpand\mathbb{\Ch@r}} \expandafter\edef\csname cal\Ch@r\endcsname{\noexpand\mathcal{\Ch@r}} \expandafter\edef\csname frak\Ch@r\endcsname{\noexpand\mathfrak{\Ch@r}} \expandafter\edef\csname scr\Ch@r\endcsname{\noexpand\mathscr{\Ch@r}} }} \makeatother \MyAlphabet{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}
記述しているのは
を簡単に書くマクロである.
これを書くことで, \MyAlphabet
に登録しているアルファベットに関して,
例えば\mathbb{C}
を\bbC
, \mathcal{L}
を\calL
のように書けるようになる.
\makeatletter \newcommand{\MyMathOperators}[1]{\@for\op:=#1\do{ \expandafter\edef\csname\op\endcsname{\noexpand\mathop{\noexpand\mathrm{\op}}\nolimits} }} \makeatother \MyMathOperators{% Ker,% Coker,% Hom,% End,% Aut,% id,% Gal,% ch,% ord,% Spec,% Specm,% Frac,% rank,% corank,% sgn,% alg,% Reg,% Sel,% Cl,% lcm,% gcd,% Ann,% alg,% }
さらに \MyMathOperators
に登録しているアルファベットに関して,
例えば\mathop{Ker} f
を\Ker f
, \mathop{Spec} R
を\Spec R
のように書けるようになる.
間違っても, Ker f
や\textrm{Ker} f
のように書いてはいけない.
このように書くと「Kerf」と斜体になってしまったり「Kerf」のように文字感覚が狭くなったりして見栄えが悪い.
(そもそも「Kerf」は文字「K」「 e」「 r」「 f」の積として認識されてしまう)
\let\Re\relax \DeclareMathOperator{\Re}{Re} \let\Im\relax \DeclareMathOperator{\Im}{Im} \let\epsilon\relax
複素数の実部を表す\Re
と虚部を表す\Im
は既に登録されている.
しかし実際に出力される記号は, 現在の慣習とは異なる記号であるように思える.
したがって一度\let\Re\relax
のように書いて, 未定義語に変更する.
その後, 数学作用素として\DeclareMathOperators{\Re}{Re}
と定義する.
(定義を削除するマクロを\MyMathOperators
の前に書いて, Re
とIm
を\MyMathOperators
の中に入れてもよい)
参考文献
新しい関数や補助関数
\renewcommand{\bar}[1]{\overline{#1}} \renewcommand{\tilde}[1]{\widetilde{#1}} \renewcommand{\hat}[1]{\widehat{#1}} \renewcommand{\epsilon}{\varepsilon}
指標の共役を書く際の\bar{\chi}
,
パラメータ付き楕円曲線のreductionを書く際の\tilde{E_{D}}
Pontryagin双対を書く際の\hat{\bbQ_p/\bbZ_p}
等,
適切なサイズの記号の装飾を使う場面が(少なくとも私は)ほとんどない.
したがって初めから\overline
, \widetilde
, \widehat
で再定義しておく.
また, \epsilon
を使ったことも一度もなく, \varepsilon
を使うことがほとんどなので, このように設定しておく.
\newcommand{\red}[1]{\textcolor{red}{#1}} % コメント用 \newcommand{\blue}[1]{\textcolor{blue}{#1}} % コメント用 \newenvironment{btl}{\begin{leftbar}\color{gray}}{\color{black}\end{leftbar}} % 行間(between the lines)埋め \let\|\relax \newcommand{\|}{\verb|} % 入力した文字をそのまま出力
最初の二つは, 論文の添削や, 後で見返したい部分を強調するため等に使用するマクロ.
\red{後で証明見返す.}
みたいな感じで使うことが多い.
三つ目は, 行間を埋める際に用いるマクロ.
証明をTeXでまとめているときに, 行間を全て埋めて書くと全体の見通しが悪くなる場合がある.
そのようなときに, 行間部分だけ\begin{hosoku}行間\end{hosoku}
と書くことで全体の流れを断ち切らないような文章表現ができる.
四つ目は, 何かしらのコマンド名をそのまま出力するためのマクロ.
\|\begin{align} e^{i\pi}+1=0 \end{align}|
のように使う.
mindflow環境
\renewcommand{\mindflowTextFont}{\normalfont\footnotesize\sffamily\itshape} % mindflow環境のテキストフォント変更 \renewcommand{\mindflowNumFont}{\normalfont\footnotesize\sffamily} % mindflow環境の数字フォント変更 \renewcommand{\mindflowLeft}{\hspace{1em}\(\succ\)} % mindflow環境の左側の設定 \renewcommand{\mindflowRight}{\(\prec\)} % mindflow環境の右側の設定 \setlength{\mindflowLineHeight}{1pt} % mindflow環境の行間調整
mindflow
環境と言って, 名前の通り本文とは別に, 自身の考え等をメモしておくための環境.
参考文献
カッコ
\DeclarePairedDelimiter{\skakko}{\lparen}{\rparen} % 括弧( ) \DeclarePairedDelimiter{\mkakko}{\lbrace}{\rbrace} % 括弧{ } \DeclarePairedDelimiter{\lkakko}{\lbrack}{\rbrack} % 括弧[ ] \DeclarePairedDelimiter{\gkakko}{\langle}{\rangle} % 括弧< > \DeclarePairedDelimiter{\abs}{\lvert}{\rvert} % 絶対値| | \DeclarePairedDelimiterX{\set}[2]{\lbrace}{\rbrace}{#1\,\delimsize\vert\,#2} % 集合{ }
mathtools
パッケージの便利なマクロ.
括弧の大きさを中の式に合わせて変更するには\left( 式 \right)
のように記述するが,
このマクロを書いておくと, \skakko*{式}
と書くだけで括弧の大きさを調節してくれる.
ちなみにskakko
は「small kakko」の略である.
あとgkakko
は生成元を記述するときに使うことが多いので
「generator kakko」の略として命名している.
絶対他に最適な命名があるはず. いい案があれば教えてください.
また, 集合を\mkakko*{元\mid 条件}
のように書くと, 中身によっては縦線\mid
が適切な大きさになってくれない.
そこで上のように\set
を定義すると, \set{元}{条件}
と書くことで縦線\mid
が自動的に挿入され, 適切な大きさで表示してくれる.
参考文献
キリル文字
\DeclareSymbolFont{cyrletters}{OT2}{wncyr}{m}{n} \DeclareMathSymbol{\Sha}{\mathalpha}{cyrletters}{"58}
Tate-Shafarevich群を記述するための設定. キリル文字のShaはデフォルトのフォントに入っていないので, 改めて追加する必要がある.
箇条書き
\renewcommand{\theenumi}{\roman{enumi}} \renewcommand{\labelenumi}{(\theenumi)} \renewcommand{\theenumii}{\theenumi-\alph{enumii}} \renewcommand{\labelenumii}{(\theenumii)}
箇条書きの項目番号の変更.
参考文献
擬似コード
\makeatletter \renewcommand{\ALG@name}{Algorithm} \makeatother \algrenewcommand{\algorithmicrequire}{\textbf{Input:}} \algrenewcommand{\algorithmicensure}{\textbf{Output:}} \algrenewcommand{\algorithmicthen}{\textbf{:}} % if then -> if : \algrenewcommand{\algorithmicelse}{\textbf{else:}} % else -> else : \algrenewcommand{\algorithmicdo}{\textbf{:}} % while do -> while : \algnewcommand{\Continue}{\textbf{continue}} \algnewcommand{\Break}{\textbf{break}}
アルゴリズムを記述するための設定. まだ納得いっていない設定なので後に修正.
プログラムコード
\lstnewenvironment{sage}[1][]{ \lstset{ language=Python, basicstyle={\ttfamily}, % 全体のフォント identifierstyle={\small}, % キーワードでないもののフォント commentstyle={\smallitshape}, % コメントのフォント stringstyle={\small}, % 文字のフォント keywordstyle={\small\bfseries}, % ndkeywordstyle={\small}, % stringstyle={\small\ttfamily}, numberstyle={\scriptsize}, numbers=left, % 左に行番号を表示 stepnumber=1, % 数字がどれだけずつ増えるか numbersep=1zw, % 数字とコードの間のスペース xleftmargin=3zw, % 左側のスペース xrightmargin=0zw, % 右側のスペース breaklines=true, % 長いlineは折り返す frame={lines}, % 枠の種類 columns=[l]{fullflexible}, lineskip=-0.5ex }}{}
このブログの筆者は, sageでコードを書くことが多いので, それに合わせた設定を行なっている. いくつか何の設定をしているか不明なところがあるので後に修正.
参考文献
リンク付け
\usepackage{hyperref} \usepackage{pxjahyper} \hypersetup{% colorlinks=true, % リンクのテキストに色を付ける linkcolor=blue, % \refによる標準リンクのテキストの色 citecolor=blue, % 参考文献リンクのテキストの色 urlcolor=blue, % URLリンクのテキストの色 }
参考文献の引用であったり, 式の参照を行った際にリンクを付けるための設定. そのリンクの文字色や囲みの色等を変更することができる. ただし, このパッケージは他のパッケージに色々と悪さをするので, なるべくプリアンブルの後半に読み込む.