Closed9

Ubuntu 24.04でLaTex環境を構築する

1111

使用する環境

  • Ubuntu 24.04
  • VS Code
  • Tex Live
  • latexmkrc
  • uplatex
  • jlreq
1111

Tex Liveのインストール

Texを使うにはとりあえず、Tex Liveを入れればいいらしい。
Tex LiveはLaTexのデファクト・スタンダードとなっているディストリビューション。

下記コマンドでインストールできる(インストールには1時間くらいかかる)。
多分必要パッケージのみに絞れば時間短縮できると思う。
aptだと古いらしいけど多分問題ない。

sudo apt install -y texlive-full

インストールできたか確認。

uplatex --version
e-upTeX 3.141592653-p4.1.0-u1.29-230214-2.6 (utf8.uptex) (TeX Live 2023/Debian)
kpathsea version 6.3.5
ptexenc version 1.4.3
Copyright 2023 D.E. Knuth.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the e-upTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the e-upTeX source.
Primary author of e-upTeX: Japanese TeX Development Community.
latexmk --version
Latexmk, John Collins, 31 Jan. 2024. Version 4.83
1111

作業ディレクトリを作る

以降はこのディレクトリで作業する。

mkdir latex
cd latex
code latex
1111

ビルド設定

デフォルトでは日本語対応していないので、設定を変更する。
英語圏だとpdftexによって、texから直接PDF出力するらしいが、pdftexは日本語対応していない。
日本語対応はplatex, uplatex, xelatex, lualatexなどがあるらしい。[1]
今回はuplatexを選定した。

.latexmkrc

ビルドはlatexmk[2]によってワンコマンドで実行できるようにする。
VS Code拡張機能があるからlatexmkの使用は必須ではないかも。

シンボリックリンクで管理する。

touch ~/.latexmkrc
ln -s ~/.latexmkrc .latexmkrc 
.latexmkrc
#!/usr/bin/env perl
$pdf_mode = 3;
$latex = 'uplatex -synctex=1 -halt-on-error -file-line-error %O %S';
$bibtex = 'upbibtex %O %S';
$dvipdf = 'dvipdfmx %O -o %D %S';
$makeindex = 'mendex %O -o %D %S';

settings.json

.vscode/settings.json
{
    "latex-workshop.intellisense.package.enabled": true,
    "latex-workshop.latex.autoClean.run": "onBuilt",
    "latex-workshop.latex.clean.fileTypes": [
        "*.aux",
        "*.bbl",
        "*.blg",
        "*.idx",
        "*.ind",
        "*.lof",
        "*.lot",
        "*.out",
        "*.toc",
        "*.acn",
        "*.acr",
        "*.alg",
        "*.glg",
        "*.glo",
        "*.gls",
        "*.ist",
        "*.fls",
        "*.log",
        "*.fdb_latexmk",
        "*.snm",
        "*.nav",
        "*.dvi",
        "*.synctex.gz"
    ],
    "latex-workshop.latex.outDir": "build",
    "latex-workshop.view.pdf.viewer": "tab",
    "latex-workshop.latex.recipes": [
        {
            "name": "latexmk",
            "tools": [
                "latexmk"
            ]
        },
    ],
    "latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-silent",
                "-interaction=nonstopmode",
                "-outdir=%OUTDIR%",
                "%DOC%"
            ],
        },
    ]
}
脚注
  1. https://qiita.com/kou-JP/items/60b63963f2ae7fdefddd ↩︎

  2. https://texwiki.texjp.org/?Latexmk ↩︎

1111

書いてみる

jlreqを使用すべきらしい[1]

test.tex
\documentclass[uplatex,dvipdfmx]{jlreq}

\usepackage{amsmath,amssymb}
\usepackage{mathtools}

\title{\LaTeX テスト}
\author{吉川 輝}

\begin{document}

\maketitle

\section{第一部}
\subsection{第一章}

この文章は \LaTeX で書かれています。


$$
  ax + by + c = 0
$$

\end{document}
脚注
  1. https://qiita.com/kou-JP/items/60b63963f2ae7fdefddd ↩︎

1111

表紙が指定されている場合

一旦内容を記入してpdfとして保存する。

\documentclass[uplatex,dvipdfmx]{jlreq}
\usepackage{pdfpages}

\begin{document}

% pdfをinclude
\includepdf[pages=-]{表紙.pdf}

% 目次を表示する
\tableofcontents

% ここから本文
\section{第一部}

\end{document}
1111

ソースコードを書く

listingsを使用する。

\usepackage{listings,jlisting}

\begin{lstlisting}
#include <iostream>

int main() {
    std::cout << "Hello world" << std::endl;
}
\end{lstlisting}

jlistingをインストールしないと、日本語のコメントがバグる。

このスクラップは3ヶ月前にクローズされました