LoginSignup
0
0

LaTeX:プリアンブルの紹介2 LuaLaTeX+ltjsarticle

Last updated at Posted at 2024-06-17

pLaTeXからLuaLaTeXへ移行

最終更新日:2024年6月17日

pLaTeXでは不便が多少あったのでLuaLaTeXに移行してみました.移行する上で参考になった記事を以下に載せます.

正直移行しようとした初めはエラーが続出し大変でしたが,1,2日頑張って調べて以前使っていたツールを使えるようになる所まで辿り着けました.
以前の記事:LaTeX:プリアンブルの紹介1 pLaTeX+jsarticle

LuaLaTeX用に新しく作成したプリアンブルを載せるので,もし自分と同じように移行しようと思っていてエラーが解決しない事があれば,参考になれば幸いです.
LuaLaTeXの情報は日本語ではまだ少なく,参考にした情報も自分の環境では上手く行かない事もあったので,色々試してみると良いと思います.

LaTeXの使用環境

使用するLaTeXエンジンはLuaLaTeX,文書クラスはltjsarticleです.
Windowsではまだ未検証(いずれ行う予定).Mac OS Sonomaで動作確認出来ています.

プリアンブル

目次

  1. 使用しているパッケージ
  2. コマンドの設定
  3. コマンドの解説

使用しているパッケージ

\makeatletter
\def\caption@documentclass{elsarticle} %エラー回避,,警告を抑止
\makeatother

%%%%%%%%%%%%%%%%%%%%用いるパッケージ%%%%%%%%%%%%%%%%%%%%
%ベース
\usepackage{savesym} %エラー回避のため,念のため
\usepackage{comment} %複数行のコメントアウト
\RequirePackage{fix-cm}

%レイアウト設定
\usepackage[top=25truemm,bottom=25truemm,left=25truemm,right=25truemm,truedimen]{geometry} %高機能なレイアウトの変更
\usepackage{bxpapersize} %今後出力用紙サイズの設定を適切に行うために,念のため
\usepackage{multicol} %多段組
\usepackage{vwcol} %多段組の拡張
\usepackage{balance} %文章の高さを揃える
\usepackage{setspace} %一部の行間スペースの調整
\usepackage{chngpage} %ページ設定

%グラフィックス
\usepackage[]{xcolor} %高機能な色変更
\usepackage[]{graphicx} %テキストや図の拡大縮小・回転
\usepackage{here} %図や表の配置オプション,floatも読み込まれる
\usepackage[absolute,overlay]{textpos} %textpos 絶対座標指定モード

%図やPDFファイルの読み込み
\usepackage{grffile} %読み込む写真のファイル名によるエラー回避,念のため
\usepackage{pdfpages} %PDFファイルの読み込み,多機能
\usepackage{wrapfig} %図に大して文の回り込み
\usepackage[hang,small,bf]{caption}
\usepackage[subrefformat=parens]{subcaption}
\captionsetup{compatibility=false}

%表
\usepackage{longtable} %複数ページに渡る表
\usepackage{booktabs, multirow} %高機能な表
\usepackage{threeparttable} %上2つで手が届かない表の微調整
\usepackage{makecell} %列見出しの作成やセル内テキストの配置
\usepackage{hhline} %二重罫線
\usepackage{bigstrut} %excel2latexで必要
\usepackage{colortbl} % 表の色付け

%見出し,段落など
\usepackage[compact]{titlesec} %見出しのカスタマイズ
\usepackage{indentfirst} %何故か段落で字下げされないので強制的に
\setlength{\parskip}{0\zw} %段落間余白
\parindent = 1\zw %段落の字下げ量

%箇条書き
\usepackage[shortlabels,inline]{enumitem} %高機能な箇条書き,shortlabelsは衝突回避
\setlist[itemize]{leftmargin=*} %itemizeを左側にずらす
\setlength{\leftmargini}{20pt} %左余白を調節する.
\setlength{\labelsep}{5pt} %6. itemと文字の間
\setlength{\itemsep}{0pt} %ブロック間の余白

%枠ボックス
\usepackage{ascmac} %複数行や数式環境で枠で囲う
\usepackage{fancybox} %部分的に枠で囲う

%数式・フラフ
\usepackage{amsmath,amssymb,onlyamsmath} %高機能な数式環境,フォントamssymb
\usepackage{mathtools} %数式環境の拡張
\let\mtdblcolon\dblcolon
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\usepackage{empheq} %場合分け,各式に数式番号
\usepackage{bm} %太字のベクトル表記
\usepackage{esint} %様々な積分記号
\usepackage{derivative} %微分積分,偏微分
\usepackage{nicematrix} %複雑な行列
\usepackage{siunitx} %SI単位系
\usepackage{textcomp} %単位記号
\usepackage[version=4]{mhchem} %化学式
\everymath{\displaystyle} %数式の書体
\usepackage{exscale} %大型演算子のフォントサイズ調整用
\usepackage[thicklines]{cancel} %数式に取り消し線,対角線を引く
\usepackage{tikz} %グラフを直接書く
\usetikzlibrary{intersections,calc,arrows.meta,positioning,shapes.arrows,bending}%tikzの機能

%リンク参照
\usepackage{xurl} %URL
\renewcommand\UrlFont{\mcfamily}
\usepackage{footnote} %脚注
\usepackage[super]{cite} %複数の文献を引用
% \usepackage[luatex,pdfencoding=auto,unicode=true,hidelinks]{hyperref} %ハイパーリンク機能,hidelinkで色をつけない
\usepackage{bookmark}
\hypersetup{
  unicode=true,hidelinks,
	bookmarksopen=false, %ブックマークを開く
	colorlinks=false, %リンクのテキストに色をつけるか,リンクに枠がつくか
	linkcolor=black, %内部参照リンク用のカラー
	citecolor=black, %文献参照リンク用のカラー
	filecolor=black, %ローカルファイル参照リンク用カラー
	urlcolor=black %外部参照urlリンク用カラー
}

%文字フォント
\usepackage[no-math]{luatexja-fontspec}
% \usepackage[no-math,deluxe]{luatexja-preset} 警告出る よくわからない
\usepackage{luatexja-otf} %よくわからない
\setmainfont[Ligatures={TeX}]{Times-New-Roman}
\setmainjfont[
  BoldFont           = {msmincho.ttc}, % フォントのttcファイルはネットからダウンロード
  BoldFeatures       = {FakeBold=6},
  ItalicFont         = {msmincho.ttc},
  ItalicFeatures     = {FakeSlant=0.33},
  BoldItalicFont     = {msmincho.ttc},
  BoldItalicFeatures = {FakeBold=2, FakeSlant=0.33}
]{msmincho.ttc}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
\setmathfont{tex-gyre-termes-math}
\newfontfamily{\tnr}{Times-New-Roman}
\newjfontfamily{\msgothic}{msgothic.ttc}
\newjfontfamily{\msmincho}{msmincho.ttc}
% Cambria-Math.ttf, stix-two-math, tex-gyre-termes-math, xits-math, latin-modern-math

% \usepackage{type1cm} %欧文フォントのサイズ指定のエラー回避
\usepackage{setspace} %行間隔の調整
\usepackage{pxrubrica} %漢字にルビをつけられる
\usepackage{ulem} %下線,波線,打ち消し線,上線
\usepackage{udline} %ulem,日本語で複数行に渡る線を引く
\usepackage{listings} %コードの貼り付け
\usepackage{lltjp-listings} % 日本語も処理
\usepackage[framed,numbered]{matlab-prettifier} %matlabコード optionでstyle=Matlab-editor, basicstyle={\mcfamily}など
\lstset{
    % basicstyle={\small\mcfamily}, % \ttfamily
    keepspaces=true, % スペースを省略せず保持
    columns=[l]{fullflexible},
    frame=tlrb, % tlrb, leftline,topline,bottomline,lines,single,shadowbox
    rulecolor=\color{black},
    backgroundcolor=\color[gray]{0.95},
    breaklines = true,
    lineskip=-0.2ex, % 行間
    numberstyle={\small},
    numbers = left,
    numbersep=10pt, % 行数の余白
    stepnumber = 1, % 行数の増間
    xrightmargin=0\zw, % 右の余白
    xleftmargin=3\zw, % 左の余白
    tabsize=2, % タブ数
    showspaces=false, % 空白の表示
    columns=fullflexible,
    moredelim=[is][\color{Red}\bfseries]{<\#}{\#>}, % ハイライト用
}
\lstdefinelanguage{MATLAB}{
  style=Matlab-editor,
  basicstyle={\mcfamily},
  numberstyle={\small\color{black}},
  lineskip=-0.2ex,
  rulecolor=\color{black},
  keepspaces=true,
  moredelim=[is][\color{Red}\bfseries]{<\#}{\#>}
}

コマンドの設定

%%%%%%%%%%%%%%%%%%%%%コマンドの設定%%%%%%%%%%%%%%%%%%%%
\makeatletter %定義に@が現れる際に必要

% 余白
\AtBeginDocument{
\setlength\floatsep{1\zw} % 図と図の間のスペース
\setlength\textfloatsep{1\zw} % 本文と図の間のスペース
\setlength\intextsep{0.5\zw} % 本文中の図のスペース
\setlength\abovecaptionskip{0truemm} % 図とキャプションの間のスペース
\setlength{\abovedisplayskip}{1\zw} % 数式の上部余白
\setlength{\belowdisplayskip}{1\zw} % 数式の下部余白
}

%見出しの書式
%明朝体はmcfamily,ゴシック体はgtfamily
%太字はbfseries,イタリック体はitshape,ローマン体はrmfamily,スモールキャピタルはscshape,サンセリフ体はsffamily,スラント体はslshape,タイプライター体はttfamily
%section
\titleformat{\section}[hang]{
  \normalsize\bfseries\mcfamily}{\arabic{section}}{.8\zw}{}
\titlespacing*{\section}{0\zw}{1.5\zw}{0\zw}
%subsection
\titleformat{\subsection}[hang]{
  \normalsize\bfseries\mcfamily}{\arabic{section}.\arabic{subsection}}{.8\zw}{}
\titlespacing*{\subsection}{0\zw}{1\zw}{0\zw}
%数式を含む見出しを作りたいとき
\newcommand{\numsection}[1]{\section{\texorpdfstring{#1}{TEXT}}}
\newcommand{\numsubsection}[1]{\subsection{\texorpdfstring{#1}{TEXT}}}

%文字
\newcommand{\rubym}{\ruby[m]} %モノルビを使う.
\newcommand{\red}[1]{\textcolor{red}{#1}} %赤いテキスト
\newcommand{\blue}[1]{\textcolor{blue}{#1}} %青いテキスト
\newcommand{\delete}[1]{\Midline{#1}} %取り消し線(日本語文章)
\newcommand{\smath}[1]{\hbox{\sout{$\displaystyle #1$}}} %取り消し線(数式環境内)
%キーワードや暗記したい単語の書式
\newcommand{\keyw}[1]{\textcolor{blue}{#1}} %キーワード
\newcommand{\Ukeyw}[1]{\textcolor{blue}{\underline{\textcolor{blue}{\: #1 \:}}}} %キーワード,下線付き
\newcommand{\memw}[1]{\textcolor{CarnationPink}{#1}}%暗記ワード
\newcommand{\Umemw}[1]{\textcolor{Black}{\underline{\textcolor{CarnationPink}{\: #1 \:}}}} %暗記ワード,下線付き
\newcommand{\vect}[1]{\overrightarrow{#1}}
\newcommand{\cnm}[1]{\textcircled{\scriptsize{#1}}} %数字を丸で囲んだ文字
\newcommand{\degree}{^\circ}
\renewcommand{\hat}{\widehat}
\renewcommand\citeform[1]{\rm[#1]} % 上付きの文献参照に[]をつける

%括弧
\newcommand{\ab}[1]{\left(#1\right)} %()で括る
\newcommand{\bab}[1]{\left\{#1\right\}} %{}で括る
\newcommand{\Bab}[1]{\left[#1\right]} %[]で括る
\newcommand{\zab}[1]{\left|#1\right|} %||で括る
\newcommand{\dzab}[1]{\left. #1 \right|} %|_{}で使う.
\newcommand{\paraAb}[1]{\noindent <#1>} %<タイトル>
\newcommand{\paraAB}[1]{\noindent <#1>\\} %<タイトル>改行
\newcommand{\paraABt}[1]{\noindent <#1>\\\indent} %<タイトル>改行+インデント

%表,図などの参照
\renewcommand{\figurename}{}
\renewcommand{\tablename}{}
\newcommand{\figref}[1]{\figurename\ref{#1}}%図の参照
\newcommand{\tabref}[1]{\tablename\ref{#1}}%表の参照
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\renewcommand{\thetable}{\thesection.\arabic{table}}
\renewcommand{\theequation}{\thesection.\arabic{equation}}
\@addtoreset{figure}{section}
\@addtoreset{table}{section}
\@addtoreset{equation}{section}
\captionsetup[figure]{format=plain, labelfont=md, labelformat=simple, margin=0pt,labelsep=quad, font=normalsize}
\captionsetup[subfigure]{format=plain, labelfont=md, labelformat=simple, margin=0pt,labelsep=quad, font=normalsize}
\renewcommand*{\thesubfigure}{(\alph{subfigure})}
\captionsetup[table]{format=plain, labelfont=md, labelformat=simple, labelsep=quad,margin=10pt,font=normalsize}
%listingの見出し
\renewcommand{\lstlistingname}{ソースコード}
\AtBeginDocument{
\renewcommand{\thelstlisting}{\thesection.\arabic{lstlisting}}
\@addtoreset{lstlisting}{section}}
\captionsetup[lstlisting]{format=plain, labelfont=md, labelformat=simple, margin=10pt,labelsep=quad, font=normalsize}


%itemizeなどで説明を書くために良く使うコマンド
\newcommand{\mdef}{\mbox{}\\}

%目次
\renewcommand{\headfont}{\bfseries\large\mcfamily} %目次のSectionの書式
\newcommand{\tableofcontentswithouttitle}{
\@mkboth{\contentsname}{\contentsname}
\@starttoc{toc}} %"目次"を消す
\newcommand{\tocnew}[2]{ %新しい目次のコマンド,目次を任意の複数行で書き,tocdepthを設定する.
\leftline{\bfseries\Large 目 次}
\setcounter{tocdepth}{#2}
\begin{multicols}{#1}
\tableofcontentswithouttitle
\end{multicols}}

%数式
\DeclareRobustCommand{\percent}{\text{\%}} % %のフォントを直す.
%微積
\newcommand{\dd}[1]{\odif{#1}} %微分d
\newcommand{\pp}[1]{\pdif{}{#1}} %偏微分p
\newcommand{\dv}[3][1]{\odv[order={#1}]{#2}{#3}} %常微分係数d/d
%\newcommand{\dvn}[2]{\odv[switch-*=true]{#1}{#2}} %常微分係数
\newcommand{\dvp}[3][1]{\pdv[order={#1}]{#2}{#3}} %偏微分係数p/p
%\newcommand{\dvpn}[2]{\pdv[switch-*=true]{#1}{#2}} %偏微分係数
\newcommand{\dvl}[3][1]{\mdv[order={#1}]{#2}{#3}} %ラグランジュ微分
%行列
\newcommand\mx[1]{\begin{matrix}#1\end{matrix}} %行列
\newcommand\pmx[1]{\begin{pmatrix}#1\end{pmatrix}} %(行列)
\newcommand\bmx[1]{\begin{bmatrix}#1\end{bmatrix}} %[行列]
\newcommand\vmx[1]{\begin{vmatrix}#1\end{vmatrix}} %行列式
\newcommand\Vmx[1]{\begin{Vmatrix}#1\end{Vmatrix}} %行列ノルム
%文章中の式に式番号を入れる
\def\EqNumText{\refstepcounter{equation}\cdots\tagform@\theequation}
%数式を呼び出した際の書式
\newcommand{\Eqref}[1]{\eqref{#1}}
% SI単位系,数式や関数を含める
\newcommand{\SIeq}[2]{\SI[parse-numbers=false]{#1}{#2}}
% 虚数と実部
\let\Re\relax
\DeclareMathOperator{\Re}{Re}
\let\Im\relax
\DeclareMathOperator{\Im}{Im}
\newcommand{\const}{\mathrm{const.}} %定数

% 確率統計
\newcommand{\npr}[2]{{}_{#1} P_{#2}}
\newcommand{\ncr}[2]{{}_{#1} C_{#2}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}

%表の書式
\newcommand{\CenterRow}[2]{
  \dimen0=\ht\strutbox%
  \advance\dimen0\dp\strutbox%
  \multiply\dimen0 by#1%
  \divide\dimen0 by2%
  \advance\dimen0 by-.5\normalbaselineskip
  \raisebox{-\dimen0}[0pt][0pt]{#2}} %行間が大きい場合,文を行間の中央に寄せる.数字は行数
\newcommand{\cellspace}{\rule[-10pt]{0pt}{28pt}} %表の中に数式を入れる場合,行間をつくる
\newcommand{\Gray}{\columncolor[gray]{0.9}}

%cline セルに色をつけた時に消える現象を避ける,黒色の線
\def\@cline#1-#2\@nil{%
  \noalign{\vskip-\arrayrulewidth}
  \omit
  \@multicnt#1%
  \advance\@multispan\m@ne
  \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
  \@multicnt#2%
  \advance\@multicnt-#1%
  \advance\@multispan\@ne
  {\CT@arc@\leaders\hrule\@height\arrayrulewidth\hfill}%
  \cr}

\makeatother

コマンドの解説

随時更新

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0