ブログ,引っ越しました
TeX: マクロ
ようやく少し分かってきたのでメモ.
・通常は\def, \newcommandで定義.
\newcommand{コマンド名}[引数の数][オプション]{定義}
・begin, endで記述する環境は\newenvironment.
\newenvironment{環境名}[引数の数]{begin}{end}
・既存のものを書き換える場合には\renewcommand
・\newcounter{コマンド名}[カウントしたいもの]
オプションは引数#1の既定値になるので,本文中で#1を省略すると自動でコンパイル時に既定値が使われる.
e.g.) \newcommand{\test}[2][red]{\color{#1} \Large #2} と書いておくと,
\test{text} → {\color{red} \Large text},
\test[green]{text} → {\color{green} \Large text},
になる.
TeX: プリアンブル 続
「subfigureでうまくrefできない問題」が解決した.
正確には,subcaptionに変えたら動いた.
調べたところ,captionと一緒に使うことが多いらしいので,それも併せて
\usepackage[hang,small,bf]{caption}
\usepackage[subrefformat=parens]{subcaption}
\captionsetup{compatibility=false}
の3行をプリアンブルに追加.
\usepackage[subrefformat=parens]{subcaption}
は\subrefのときに(a)と書くための指定.
parensがないと\ref{}\subref{}で1.1 a.あると1.1 (a).
ついでに少し楽になるかと思ってnewcommandを書いてみた.
\newcommand{\figsubref}[2]{図~\ref{fig:#1}\subref{fig:#2}}
\ref{fig:foo}, \subref{fig:bar}なら,\figsubref{foo}{bar}で1.1 (a)と参照できる.