subfilesを使ってみんなで記事を書く、しおりも出す
こんにちは、びしょ〜じょです。
この度、『Dragon University 技術書典5』を手にとっていただいて誠にありがとうございました。
70部弱売れたのでええ感じでした。ありがとうございました。 pic.twitter.com/dYxhhgDnnx
— びしょ〜じょ (@Nymphium) October 8, 2018
"70部弱"とありますが実際は"70部強"です。 重ねてありがとございました。
さて、ここからが大事だ。 大事な話をする。
Dragon Universityは近々ダウンロード販売をやるようなのでお待ち下さい、物理媒体を購入した方はnページ目m行目s文字目~t文字などのパスフレーズを入力すると無料でゲットできるようにする(はず)
— びしょ〜じょ (@Nymphium) October 8, 2018
してました。
追記20181018
もうはじまってる!!!
https://dragonuniversity.booth.pm/items/1055860
追記おわり
さて、LaTeX文書からPDFを作成してpublishした人の多くはhyperrefパッケージを使っているかと思います。 hyperrefにはしおりを作る機能があります(図1)。

今回我々はsubfilesで各々がファイルを書いてプロジェクトのルートのmain.texで各人のmainファイルを読むようにしました。
.
├── authors
│ ├── ore
│ │ └── main.tex
│ └── other
│ └── main.tex
└── main.tex
......
\begin{document}
\subfile{authors/ore/main.tex}
\subfile{authors/other/main.tex}
\end{document}
src/latex-subfiles/authors/ore/main.tex
\documentclass{subfiles}
\author{ほげほげ}
\title{あああ}
\begin{document}
\maketitle
\section{はじめに}
\subsection{ほげ}
\section{おわりに}
\end{document}
src/latex-subfiles/authors/other/main.tex
\documentclass{subfiles}
\author{other}
\title{別の話}
\begin{document}
\maketitle
\section{はじめに}
\subsection{ほげ}
\section{おわりに}
\end{document}
subfilesで\maketitle
を使うと各記事のタイトルを良い感じにいれられないので改造する。
......
\makeatletter
\renewcommand{\maketitle}{%
\clearpage
\newpage\null
\vskip 2em
\begin{center}%
\let\footnote\thanks
{\LARGE \textbf{\@title} \par}% タイトル
\vskip 1.5em
{\large
\lineskip .5em
\begin{flushright}
\@author % 著者名
\end{flushright}
\par}%
\end{center}%
\par\vskip 1.5em
\ifvoid\@abstractbox\else\centerline{\box\@abstractbox}\vskip1.5em\fi
\setcounter{section}{0}% ミソ
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{footnote}{0}
}
\makeatother
......
この辺は好みによる。
今回はltjsarticleの\maketitle
コマンドを改造している。
section等のカウンタを0で初期化しているのがミソで、これをしないと各記事のカウンタが連番になってしまう。
しかしそうするとしおりが壊れる(図2)。

hyperrefパッケージのオプションにhypertexnames=false
を渡すことで解決する。
......
\usepackage[%
pdfencoding=auto% 文字化け防止
, hypertexnames=false% ←
, luatex]{hyperref}
......

図1のように記事名もしおりに入れたい。
記事名の子に各セクションが来てほしいので。\maketitle
に手を加える。
......
\renewcommand{\maketitle}{%
\clearpage
\addcontentsline{toc}{part}{{\large \@title}}% これ
\newpage\null
......
この\large
指定は目次のためである。
親子関係はsectionの上に来てほしいのでchapterかpartにする。
目次はchapterよりもpartのほうが見栄えが良かったのでpartにした。
そしてまた壊れる。壊れるなぁ…。

ここでおもむろに\phantomsection
を挿入する。

......
\renewcommand{\maketitle}{%
\clearpage
\phantomsection% addcontenstlineの前に追加
\addcontentsline{toc}{part}{{\large \@title}}
\newpage\null
......
これでやっと図1のようになった。
ということでpdf版制作にもワザがありました。 表紙の"interpr i ter"も修正されていると思いますので、近々出るpdf版もよろしくおねがいします。