はやし雑記

はやしです


macOSにLaTeX環境を構築

  • GUIはインストールせず,VSCodeで書く
  • latexmkrcを使う
  • uplatexを使う
  • Mendeleyの吐くlibrary.bibを使う

TeXLive

TeX Live/Mac - TeX Wiki

$ brew cask install mactex-no-gui
$ sudo tlmgr update --self --all
$ sudo tlmgr paper a4

latexindentのためにPerlなどが必要なので

$ brew install perl cpanm
$ cpanm Log::Log4perl Log::Dispatch::File YAML::Tiny File::HomeDir Unicode::GCString

VSCode

LaTeX Workshop - Visual Studio Marketplace

Latex Workshopをインストール

.vscode/settings.json

{
    "latex-workshop.latex.outDir": "out",
    "latex-workshop.latex.recipes": [
        {
            "name": "latexmk",
            "tools": [
                "copy_bib",
                "latexmk"
            ]
        },
    ],
    "latex-workshop.latex.tools": [
        {
            "name": "copy_bib",
            "command": "cp",
            "args": [
                "/path/to/library.bib",
                "%DIR%"
            ]
        }, 
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-silent",
                "-outdir=%OUTDIR%"
            ],
        },
    ],
}

copy_bibでMendeleyの吐くlibrary.bibをコピーしてくる

latexmkrc

#!/usr/bin/env perl
$pdf_mode = 3;
$latex = 'uplatex -halt-on-error';
$latex_silent = 'uplatex -halt-on-error -interaction=batchmode';
$bibtex = 'upbibtex';
$dvipdf = 'dvipdfmx %O -o %D %S';
$makeindex = 'mendex %O -o %D %S';

uplatex を使うようにする

TeX

\documentclass[a4paper, 11pt, dvipdfmx]{ujarticle}

\usepackage[top=20truemm,bottom=25truemm,left=22truemm,right=22truemm]{geometry}
\usepackage[dvipdfmx]{graphicx}

\begin{document}
\title{タイトル}
\author{なまえ}
\date{}

\maketitle

\section{せくしょん}

\bibliographystyle{unsrt}
\bibliography{library}

\end{document}