LaTeX関連のめちゃくちゃ便利な機能たち
はじめに
論文を書くようになって色々と機能を使わないと書くのが大変になってきたため、色々と導入してみました。それの備忘録かつこんなの使えると便利!っていうのがまとまってるといいなと思ったので記事の執筆に至りました。
ファイル分割
1つのtexファイルに全ての内容を書いてしまうと、編集しづらくなったりなどといった不便が生じます。したがって分量のある文書を作成する際は、SectionやChapterごとにファイルを分割するのが一般的です。
方法
\documentclass{hoge-thesis} \usepackage{docmute} \input{setting} \begin{document} \include{1-introduction} %\include{2-hoge} \end{document}
\documentclass{hoge-thesis} \input{setting} \begin{document} \section{introduction} hogehoge... \end{document}
% その他のパッケージなど % \usepackage{...}
1. 分割するファイル(ここではsetting.texと1-introduction.tex)を作成
2. master.texでdocmuteパッケージを読み込む
3. master.texおよび1-introduction.texに\input{setting}によりsetting.texを読み込む
4. master.texに\include{1-introduction}で1-introduction.texを挿入
※\input{}および\include{}にはファイル名の.texを外したものを書いてください。
ちょっとだけ説明
参考
bibtex
bibtexを用いることで100個など多数ある参考文献の記載をとても楽にできます。
方法
\begin{document} 〜らの研究[\cite{test}]によると〜 %... \bibliography{reference} \bibliographystyle{junsrt} %.. \end{document}
@article{test, author="Mairittha, Nattaya and Mairittha, Tittaya and Inoue, Sozo", title="On-Device Deep Learning Inference for Efficient Activity Data Collection", journal="Sensors", ISSN="1424-8220", publisher="MDPI", year="2019", month="aug", volume="19", number="15", pages="3434-1-3434-20", URL="https://ci.nii.ac.jp/naid/120006719301/", DOI="", }
reference.bibの内容は大抵のサイトからアクセスでき、それをコピペしてくるだけでokです。
1. mastex.texをコンパイル
2. 以下のどちらかのコマンドでデータベースの参考文献を反映
・和文 → bibtex {TeXファイル名}
・英文 → bibtex {TeXファイル名}
3. master.texを3回コンパイル
引用や参考文献の表示順などについては以下の記事を参照してください。
qiita.com
latexmk
latexmkはplatexやdvipdfmx、bibtexなど複数あって面倒な処理をコマンド一つで全てやってくれるやつでMakefileに近いですが、設定が遥かに楽なものになっているので、こちらの方が良いかなと思います。
設定
~/.latexmkrcを作成します。
#!/usr/bin/env perl $pdf_mode = 3; $latex = 'platex -halt-on-error'; $latex_silent = 'platex -halt-on-error -interaction=batchmode'; $bibtex = 'pbibtex'; $dvipdf = 'dvipdfmx %O -o %D %S'; $makeindex = 'mendex %O -o %D %S';
実行
$ latexmk master.tex
これだけで.texから.pdfを作成してくれます。また上記の設定では記述していませんが、この後pdfビューワーを開いてくれるなどといった設定も可能です。詳細は以下をどうぞ。
qiita.com
qnighy.hatenablog.com