どうも、お久しぶりです。いつの間にかB3となったYKでございます。
わたしはよくTeXを使って授業のノートをまとめたり問題を解いたりしているのですが、使いやすいようにコマンドを改造していたら割ととんでもないことになっていましたので、いっそエンタメのようにご紹介してやろうかなという感じの記事です。
まず言っておきたいのが、この設定は使いやすいはそうなのですが、共同編集などをしているときは絶対に使わないほうがいいです。
編集しようとしたら突然 \brk{$\ddx\ds\int_a^bf(x)\dx=f(x)$}
と書かれていても意味わからないですしね。あくまで個人用でしたら、ぜひ真似していただければ。
……ただ、\newcommand
系が使えない環境だといつもの癖が入力の邪魔をしてくるという致命的な短所が合ったりはします。
なお、ぼくはほとんどを \input
コマンドを使って別のファイルで管理しています。\input{{C:/~~~~~/macro}}
的な感じですね。.tex
の拡張子は必要ないらしいです。
あ、pLaTeX を使っています。
macro.tex
内 % ------ Inputting Package ------
\usepackage[top=20truemm,bottom=16truemm,inner=7truemm,outer=7truemm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,booktabs,array,amsmath,amssymb,amsthm}
\usepackage{tcolorbox,multicol,vwcol,mathrsfs}
\usepackage{xparse,mleftright,cancel,tasks,ulem,here,fancyhdr,wrapfig,mathtools}
\usepackage[inline]{enumitem}
\usepackage{kotex,tikz,upgreek}
\usetikzlibrary{calc}
\usepackage[deluxe]{otf}
\usepackage[font=small,labelsep=none]{caption}
\usepackage[dvipsnames]{xcolor}
\usepackage{adjustbox}
\usepackage{stmaryrd}
特筆すべきものはあまり気がしますが、tikz
, upgreek
パッケージは最近あんま使わないかなという感じです。そのうち消します。
残りはほとんど使います。どんだけパッケージに頼ってるかが分かりますね。
あと enumitem
パッケージの inline
オプションって確か tasks
パッケージがあるのを知らなかった頃の試行錯誤の産物なのでこっちもそのうち消えるかと。
文書内に入れているのはこちら。
\documentclass[dvipdfmx,a4paper,titlepage,9pt]{jsarticle}
\input{{C:/Users/Lenovo/texlive/2023/Macros/macro}}
\usepackage[%
dvipdfmx,%
setpagesize=false,%
bookmarks=true,%
bookmarksdepth=2,%
bookmarksnumbered=false,%
colorlinks=true,%
linkcolor=blue,%
hidelinks,%
pdftitle={},%
pdfsubject={},%
pdfauthor={},%
pdfkeywords={}%
]{hyperref}
\usepackage{pxjahyper}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{\tb{``~~~~'' Class Notes}} % 主に科目名とかのやつ
\fancyhead[C]{}
\fancyhead[R]{$\Equiv$ (@\,\!Equiv\_\_)} % 学校用の場合実名を書きます
\fancyfoot[L,R]{}
\fancyfoot[C]{\tr{\thepage}}
\rnc{\headrulewidth}{0.4pt}
\usepackage{okumacro} % ふりがな用パッケージ
\usepackage[noalphabet, unicode]{pxchfon}
\setminchofont[0]{GenEiKoburiMin6-R.ttf} % 源瑛こぶり明朝にフォント変更
\documentclass
に関しては文書内にないとダメだった気がする。fancyhdr
パッケージは別に macro.tex
内にあってもいい気はしますけど、癖になっちゃいましたね。
% ------ Re-commands ------
\newcommand{\nc}{\newcommand}
\nc{\rnc}{\renewcommand}
\nc{\ndc}{\NewDocumentCommand}
\nc{\rndc}{\RenewDocumentCommand}
% ------ Pre-settings ------
\setlength{\columnseprule}{0.4pt}
\graphicspath{{C:/~~~~~/Figures/}} % 経路はごまかしただけです
\tcbuselibrary{raster,skins}
\rnc{\familydefault}{\sfdefault}
\(re)newcommand
と \(Re)NewDocumentCommand
は最初から縮めています。
その下はよく multicols*
環境を使うのでその分ける線の太さとか、図の経路とか、いろいろ。
% -------------- Mathematical Symbols --------------
%% ------ Letters ------
\nc{\NN}{\mathbb{N}}
\nc{\ZZ}{\mathbb{Z}}
\nc{\QQ}{\mathbb{Q}}
\nc{\RR}{\mathbb{R}}
\nc{\II}{\mathbb{I}}
\nc{\CC}{\mathbb{C}}
\rnc{\d}{\,\mr d}
\nc{\D}{\scalebox{0.85}[1]{$\mi{\Delta}$}}
\nc{\dx}{\,\mr dx}
\nc{\dy}{\,\mr dy}
\nc{\dt}{\,\mr dt}
\ndc{\dd}{mm}{\frac{\mr{d}#1}{\mr{d}#2}}
\nc{\ddx}{\frac{\mr{d}}{{\mr{d}}x}}
\nc{\ddt}{\frac{\mr{d}}{{\mr{d}}t}}
\nc{\del}{\partial}
\ndc{\rr}{mm}{\frac{\del#1}{\del#2}}
\nc{\Nabla}{\scalebox{0.8}[1]{$\bs{\nabla}$}}
\nc{\Nb}{\Nabla}
\mr
が連続していますが、\mathrm
を再定義したものです。そのうち出てきます。d
から始まるコマンドはご覧の通りすべて微分演算子とかですね。
\Delta
と \D
の比較
あとはなんでしょう、\del
は普通に \partial
が長いし覚えづらいしで変えましたってくらいでしょうか。
%% ------ Symbols ------
\nc{\tri}{\triangle}
\nc{\sq}{\square}
\nc{\bsq}{\blacksquare}
\nc{\Sq}{$\sq$}
\nc{\Bsq}{$\bsq$}
\nc{\Emptyset}{\varnothing}
\nc{\To}{\Rightarrow}
\nc{\from}{\leftarrow}
\nc{\From}{\Leftarrow}
\nc{\longto}{\longrightarrow}
\nc{\Longto}{\Longrightarrow}
\nc{\longfrom}{\longleftarrow}
\nc{\Longfrom}{\Longleftarrow}
\nc{\Lrarrow}{\Longleftrightarrow}
\nc{\ifff}{\Longleftrightarrow}
\nc{\lmapsto}{\,\longmapsto\,}
\nc{\notlongto}{\mathrel{\longto\h{-14}/}\h6}
\ndc{\xLrarrow}{m}{\overset{#1}{\Longleftrightarrow}}
\ndc{\xto}{m}{\xrightarrow{#1}}
\ndc{\xfrom}{m}{\xleftarrow{#1}}
\ndc{\xTo}{m}{\xRightarrow{#1}}
\ndc{\xFrom}{m}{\xLeftarrow{#1}}
\nc{\defar}{\xLrarrow{\tx{def}}}
\nc{\FA}{\tx{\raisebox{-0.065mm}{\scalebox{1.035}{\rotatebox[origin=c]{180}{\reflectbox{$\Finv$}}}}}\forall}
\nc{\for}{\tx{\raisebox{-0.065mm}{\scalebox{1.035}{\rotatebox[origin=c]{180}{\reflectbox{$\Finv$}}}}}}
\nc{\Fa}{\tx{\raisebox{-0.065mm}{\scalebox{1.035}{\rotatebox[origin=c]{180}{\reflectbox{$\Finv$}}}}}^\forall}
\nc{\Pt}{\partial}
\rnc{\iint}{\int\h{-8}\int}
\rnc{\iiint}{\int\h{-8}\int\h{-8}\int}
\nc{\Ch}{\UTF{2713}}
\nc{\Cdot}{$\cdot$}
\Sq
と \Bsq
は証明終わりのやつで結構使うのでやっておきました。
空集合は
\FA
と \Fa
に関しては、教授が'for all'の略をそう書くことが多くて定義したという感じですかね。普通は
\FA
, \Fa
の使用例。よく使われるのは \Fa
のほう。
\Ch
はチェック記号。これ→✓。「教授が指定した問題だよー」という目印用です。
%% ------ Operations ------
\nc{\sseq}{\subseteq}
\nc{\Sim}{\mathrel{\text{\UTF{223D}}}}
\nc{\lqs}{\leqslant}
\nc{\gqs}{\geqslant}
\nc{\nex}{\not\!\exists}
\nc{\Circ}{\mathrel{\raisebox{0.4pt}{\scalebox{0.8}{$\circ$}}}}
\nc{\union}{\cup}
\nc{\Union}{\bigcup}
\nc{\inter}{\cap}
\nc{\Inter}{\bigcap}
\nc{\para}{\mathrel{\:\mkern-5mu\clipbox{0 0.7ex 0 0}{${\sslash}$}}}
\Sim
は中高の教科書で使う相似の記号です。\sim
は同型(isomorphic)や対等(equipotent)で、\Sim
は図形での相似で使い分けてますね。
\sim
と \Sim
の比較
\Circ
は合成のやつですが、元々の \circ
が大きいのが気に食わなくて縮小して位置調整したやつですね。
\para
は平行。元々は \parallel
ですが、斜めなのが好きでこっちも定義しました。
\parallel
と \para
の比較
%% ------ Functions ------
\nc{\opn}{\operatorname}
%%% Analysis
\nc{\sgn}{\opn{sgn}}
\nc{\dom}{\opn{dom}}
\rnc{\P}{\msc{P}}
\nc{\mesh}{\opn{mesh}}
%%% Linear Algebra
\nc{\adj}{\opn{adj}}
\nc{\Span}{\opn{Span}}
\nc{\rank}{\opn{rank}}
\nc{\nullity}{\opn{nullity}}
\nc{\range}{\opn{range}}
\nc{\coef}{[{}\cdot{}]}
%%% Calculus
\nc{\comp}{\opn{comp}}
\nc{\proj}{\opn{proj}}
\nc{\Var}{\opn{Var}}
%%% Metric Space
\nc{\cod}{\opn{cod}}
\nc{\dist}{\opn{dist}}
\nc{\diam}{\opn{diam}}
\nc{\id}{\opn{id}}
%%% Machine Learning
\nc{\argmax}{\opn*{arg\,max}}
\nc{\argmin}{\opn*{arg\,min}}
%%% Discrete Maths
\ndc{\perm}{mm}{{}_{#1}\mr P_{#2}}
\ndc{\combi}{mm}{{}_{#1}\h{-1}\mr C_{#2}}
ここはあんまり解説することはなさそう。
科目別に使う関数を分けています。
\cod
は確か終域(codomain)だったはず。\perm
と \combi
は順列・組合せの数の
%% ------ Fonts/Colors ------
\ndc{\brk}{m}{{\color{BrickRed}#1}}
\nc{\bs}{\boldsymbol}
\nc{\mb}{\mathbf}
\nc{\mi}{\mathit}
\nc{\mr}{\mathrm}
\nc{\msc}{\mathscr}
\rnc{\mc}{\mathcal}
\nc{\mf}{\mathfrak}
\nc{\tx}{\text}
\nc{\tb}{\textbf}
\nc{\ti}{\textit}
\nc{\ts}{\textsf}
\nc{\tr}{\textrm}
\ndc{\tbs}{m}{\textbf{\textsf{#1}}}
\definecolor{TGreen}{cmyk}{0.36,0,0.59,0.49}
ここまでしたくはなかったんですがねぇ。なんかぜんぶめっちゃ使うのでこうなりました。\texttt
まだ設定していないのですが、\tt
って何かありましたっけ?
%% ------ Decorations ------
\nc{\ol}{\overline}
\nc{\ul}{\underline}
\rnc{\Vec}{\overrightarrow} % 矢印が大きいので小文字には向かない
\ndc{\sg}{m}{\ol{\mr{#1}}}
\ndc{\inner}{m}{\overset{\text{\raisebox{-1pt}{$\circ$}}}{#1}}
\ndc{\Inner}{m}{\overset{\text{\raisebox{-1pt}{$\circ$}}}{\arc{#1}}}
\nc{\arc}[1]{
\tikz [baseline = (N.base), every node/.style={}] {
\node [inner sep = 0pt] (N) {$#1$};
\draw [line width = 0.4pt] plot [smooth, tension=1.3] coordinates {
($(N.north west) + (0.1ex,0)$)
($(N.north) + (0,0.5ex)$)
($(N.north east) + (0,0)$)
};
}
}
\nc{\inpd}{\ang{{}\cdot{},{}\cdot{}}}
\nc{\Gray}{\color{Gray}}
上下線などの装飾ですね。\inner
は距離空間論でのinner set。
……なんで \Gray
こっちにおいたんだろ。
%% ------ Bracket/Matric ------
\ndc{\bm}{m}{\begin{bmatrix}#1\end{bmatrix}}
\ndc{\Bm}{mm}{\left[\!\begin{array}{#1}#2\end{array}\!\right]}
\ndc{\mt}{m}{\begin{matrix}#1\end{matrix}}
\ndc{\Mt}{mm}{\begin{array}{#1}#2\end{array}}
\ndc{\abs}{m}{\left|#1\right|}
\ndc{\nrm}{m}{\lVert#1\rVert}
\ndc{\fl}{m}{\lfloor #1\rfloor}
\ndc{\Fl}{m}{\left\lfloor #1\right\rfloor}
\ndc{\ceil}{m}{\lceil #1\rceil}
\ndc{\Ceil}{m}{\left\lceil #1\right\rfloor}
\ndc{\Nrm}{m}{\left\lVert#1\right\rVert}
\ndc{\ang}{m}{\left\langle#1\right\rangle} % 主に内積
\ndc{\Det}{mm}{\abs{\!\begin{array}{#1}#2\end{array}\!}}
\nc{\Mid}{\,\middle|\,}
元々あった行列がちょっと気に入らなくてarray環境で作り直してます。
あとは \l~
, \r~
タイプのやつを縮めたり。\abs{x}
意外と便利ですよ。
%% ------ Question Box (with pts) ------
\newenvironment{qtbox}[2][]
{\vspace{9pt}
\begin{tcolorbox}[enhanced,title={{\bf #1}\;{\sf (#2 pts)}},
attach boxed title to top left=
{xshift=3mm, yshift*=-\tcboxedtitleheight/2},
colframe=white!30!black,
colbacktitle=white!30!black,
colback=white]}
{\end{tcolorbox}}
%% ------ Question Box (wo pts) ------
\newenvironment{Qtbox}[1][]
{\vspace{9pt}
\begin{tcolorbox}[enhanced,title={\tb{#1}},
attach boxed title to top left=
{xshift=3mm, yshift*=-\tcboxedtitleheight/2},
colframe=white!30!black,
colbacktitle=white!30!black,
colback=white]}
{\end{tcolorbox}}
\newenvironment{QTbox}[2][]
{\vspace{9pt}
\begin{tcolorbox}[enhanced,title={\tb{#1}: #2},
attach boxed title to top left=
{xshift=3mm, yshift*=-\tcboxedtitleheight/2},
colframe=white!30!black,
colbacktitle=white!30!black,
colback=white]}
{\end{tcolorbox}}
なんかややこしい分け方をしていますが、qtbox
, Qtbox
, QTbox
の違いは
問題名+得点あり / 問題名のみ / 問題名+注釈です。attach boxed title to top left
オプション結構おすすめだったり。
%% ------ Proving Box ------
\newenvironment{pfbox}[1][]
{\small
\begin{tcolorbox}[enhanced,title={{\color{Black}\sf pf. #1}},
leftrule=0mm,rightrule=0mm,toprule=0.2mm,bottomrule=0.2mm,sharp corners,
attach boxed title to top left=
{xshift=3mm, yshift*=-\tcboxedtitleheight/2},
boxed title style=
{leftrule=0.2mm,rightrule=0.2mm,toprule=0mm,bottomrule=0mm,sharp corners},
colframe=white!60!black,
coltitle=white,
colbacktitle=white,
colback=white]\color{white!40!black}}
{\end{tcolorbox}}
\newenvironment{Pfbox}[1][]
{\small
\begin{tcolorbox}[enhanced,title={{\color{Black}\sf pf. #1}},
leftrule=0mm,rightrule=0mm,toprule=0.2mm,bottomrule=0.2mm,sharp corners,
attach boxed title to top left=
{xshift=3mm, yshift*=-\tcboxedtitleheight/2},
boxed title style=
{leftrule=0.2mm,rightrule=0.2mm,toprule=0mm,bottomrule=0mm,sharp corners},
colframe=white!60!black,
coltitle=white,
colbacktitle=white,
colback=white]\color{white!40!black}
\begin{proof}[]}
{\end{proof}
\end{tcolorbox}}
\makeatletter
\renewenvironment{proof}[1][\proofname]{\par
\pushQED{\qed}%
\normalfont \topsep6\p@\@plus6\p@\relax
\trivlist
\item\relax
{\itshape
#1\@addpunct{}}\hspace\labelsep\ignorespaces
}{%
\popQED\endtrivlist\@endpefalse
}
\makeatother
\rnc{\qedsymbol}{\Bsq}
proof
環境は「証明名.」でのピリオドをなくしたいがために再定義してます。
特徴としては、タイトルには縦線のみ、枠には横棒のみを残していてすっきり感を出しました。……出せてたらいいなと思います。
設定に少し苦労はしましたが。
Pfbox
と pfbox
環境の違いは中に証明があるかどうかですね。pfbox
は中に複数個の証明を入れたいときに使います。
%% ------ Solving Box ------
\newenvironment{solbox}[1][]
{\small
\begin{tcolorbox}[enhanced,title={{\color{Black}\sf sol. #1}},
leftrule=0mm,rightrule=0mm,toprule=0.2mm,bottomrule=0.2mm,sharp corners,
attach boxed title to top left=
{xshift=3mm, yshift*=-\tcboxedtitleheight/2},
boxed title style=
{leftrule=0.2mm,rightrule=0.2mm,toprule=0mm,bottomrule=0mm,sharp corners},
colframe=white!60!black,
coltitle=white,
colbacktitle=white,
colback=white]\color{white!40!black}
\begin{proof}[]}
{\end{proof}\end{tcolorbox}}
pfbox
とほぼ一緒なので詳しい説明は割愛します。
% -------------- Titles Presets --------------
\ndc{\Ltitle}{mm}{\tb{\color{TGreen}\Large\h{-9}\S #1. \ul{#2}}\v7}
\ndc{\ltitle}{m}{\tb{\large\hs{-5}$\cdot$ {\color{TGreen}#1}}}
\ndc{\stitle}{m}{\tb{\color{TGreen}#1}}
\ndc{\LTitle}{mm}{\tb{\color{TGreen}\Large\h{-9}\S #1. \ul{#2}}\v7}
\ndc{\lTitle}{mm}{\tb{\large\hs{-5}$\cdot$ {\color{TGreen}#1 #2}}}
\Ltitle
は小単元(セクション)用、\ltitle
は単元内のかたまり用、\stitle
は概念の説明用とかです。
まとめノート用のやつですね。
以上! とても長くなりましたが、ここまでお読みいただきありがとうございました。
参考になられた方……は…………あまりいないと思いますが、\(re)newcommand
の良さが伝わったらいいな、と思います(?)。
それでは、また別の記事でお会いしましょう。