1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LaTeX でメモなし版・あり版をビルドする方法

1
Posted at

LaTeX 文書を作成するとき、「対象の箇所を含めない版も含める版もビルドしたい」ということもあると思います。例えば以下のような場合です。

  • 英語原稿だが、段落ごとに日本語も書いて英語のみ版・日本語あり版をビルドしたい。
  • より一般に、原稿中にメモを書いてメモなし版・あり版をビルドしたい。

このような場合に、日本語なし版 main.pdf と、日本語あり版 main-jp.pdf をビルドする方法を記します。結論から言うと、\excludecomment{環境名} を使用します。

関連記事

  1. Latexの出力内容を切り替える - Qiita
    • 本記事は上記記事とゴール・手段が同じですが、本記事では出力を切り替えるためにコメントアウトしたりしなかったりしなくて済む運用などを示します。

方法

以下では対象の環境名を jp とします (お好きに変えてください)。
ビルドエンジンとドキュメントクラスもご利用のものに変えていただけます。

以下のように main.tex, main-jp.tex, content.tex を作成すれば、

  • latexmk -lualatex main.tex で英語のみ版 main.pdf がビルドできます。
  • latexmk -lualatex main-jp.tex で日本語あり版 main-jp.pdf がビルドできます。
main.tex
\documentclass[a4paper,10pt]{ltjsarticle}
\usepackage{comment}
\excludecomment{jp}
\input{content}
main-jp.tex
\documentclass[a4paper,10pt]{ltjsarticle}
\usepackage{comment}
\includecomment{jp}
\input{content}
content.tex
\usepackage[top=1.3cm,bottom=1.3cm,left=1.7cm,right=1.7cm]{geometry}
\begin{document}

\section{Intoroduction}

I love dogs.

\begin{jp}
犬が好きです。
\end{jp}

I love cats, too.

\begin{jp}
猫も好きです。
\end{jp}

\end{document}

備考として、

  • content.tex を編集していってください (ファイル名はお好きに変えて構いません)。
  • 上記の例のように「英語段落 → 日本語段落 → 英語段落 → 日本語段落 → ...」と書いていく場合でも、図や表や数式については繰り返さないことをおすすめします (番号がずれるため)。「英語段落 → 日本語段落 → 表 → 英語段落 → 日本語段落 → ...」のようにするのがおすすめです。

以下は、併用すると便利かもしれない Tips です。

Tips 1. 対象の箇所に文字色を付ける

main-jp.tex を以下のように書き換えると、jp 環境の文字に色が付きます。

main-jp.tex
\documentclass[a4paper,10pt]{ltjsarticle}
\usepackage[dvipsnames]{xcolor}
\newenvironment{jp}
  {\begingroup\color{OliveGreen}}
  {\endgroup}
\input{content}

Tips 2. 対応を明確にする

「英語の段落と日本語の段落が対応する」ような場合に、en 環境も用意すると対応が明確になります。ビルドされる文書に何も影響はないですが、誰かに翻訳・添削を依頼したいときなどにはこうしておくとわかりやすいかもしれないです。

main.tex
\documentclass[a4paper,10pt]{ltjsarticle}
\usepackage{comment}
\excludecomment{jp}
\newenvironment{en}{}{}
\input{content}
content.tex
\usepackage{luatexja-fontspec}
\begin{document}

\section{Intoroduction}
\begin{en}
I love dogs.
\end{en}

\begin{jp}
私は犬が好きです。
\end{jp}

\end{document}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?