Skip to content

Instantly share code, notes, and snippets.

@TakesxiSximada
Last active May 7, 2020 14:36
Show Gist options
  • Save TakesxiSximada/421f8a7978634b14c6daa3ed9a0af2c0 to your computer and use it in GitHub Desktop.
Save TakesxiSximada/421f8a7978634b14c6daa3ed9a0af2c0 to your computer and use it in GitHub Desktop.
EmacsとLaTeXを使ってOrg-modeのファイルからPDFを生成する
README.aux
README.dvi
README.log
README.out
README.tex
README.toc

EmacsとLaTeXを使ってOrg-modeのファイルからPDFを生成する

TeX系ツールの実装について

TeXには色々な実装が存在する。 どれがどの流れを汲むかについてはこちらが参考になった。

Texについて

TeXはtug.orgのSVNでホスティングされている。 https://www.tug.org/svn/texlive/

https://www.ctan.org/tex-archive/systems/knuth/dist/tex

LaTeXについて

LaTeXはGithubでホスティングされている。 https://github.com/latex3/latex2e

MacTeXのインストール

macOS用に構成されたMacTeXというパッケージが配布されている。

http://www.tug.org/mactex/mactex-download.html

今回はMacTeX 2020が配布されていたのでそれを使うことにした。

このパッケージはpkgファイル自体が3.6GBほどで、かなり大きい。以下にはミラーサイトがまとめて掲載されていた。

https://texwiki.texjp.org/?MacTeX#mirror

Sphinx Users GroupのWebページにもMacTeXの解説ページがあった。参考にすると良い。

https://sphinx-users.jp/cookbook/pdf/latex-install-osx.html

ちなみに今回はuplatexを使うが uplatex –version と実行すると次のように表示された。

e-upTeX 3.14159265-p3.8.3-u1.26-191112-2.6 (utf8.uptex) (TeX Live 2020)
kpathsea version 6.3.2
ptexenc version 1.3.8
Copyright 2020 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: Peter Breitenlohner.

e-pTeXについてはTeX系ツールの実装についてで紹介したリンク先のWebページが参考になる。

ファイルの生成

Org-modeからTeXファイルを生成

この記事はOrg-modeで記述している。 Org-modeにはorg-publishというライブラリがあり Org-modeのドキュメントからTeXファイルを生成できる。 手動でTeXファイルを作成しても良いが 今回はorg-publishを使ってTeXファイルを生成することにした。

org-latex-export-to-latex を実行するとカレントバッファからTeXファイルが生成される。

org-latex-export-to-latex RET

これはEmacsのOrg-modeの機能だ。

Org-modeについて

https://orgmode.org/ja/

TeXファイルからdviファイルを生成

TeXファイルからdviファイルを生成するにはuplatexコマンドを使う。

uplatex README.tex

実行すると README.dvi が生成される。

dviファイル

デバイス非依存の組版用命令フォーマット。 仕様は文書化されているわけではなく、実装が仕様になっている模様。 ただし、どこにその実装があるかはわからなかった。

DVI formatについてのドキュメントの中で命令について説明されている。 https://www.ms.u-tokyo.ac.jp/~oshima/dviout/dvi.html#cmd

Wikipediaでの説明 https://ja.wikipedia.org/wiki/DVI_(%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88)

dviファイルからPDFを生成

dviファイルからPDFを生成するにはdvipdfmxコマンドを使う。

dvipdfmx README.dvi

実行すると README.pdf が生成される。

実行環境

PCMacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
OSmacOS Mojave 10.14.6(18G103)
Emacs27.0.50 (self build)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
.DEFAULT_GOAL := build
.PHONY: build
build:
uplatex README.tex
dvipdfmx README.dvi
.PHONY: clean
clean:
rm -f README.aux README.dvi README.log README.out README.pdf README.tex README.toc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment