Multilingual Document
Question
I would like to follow the principle of "don't repeat yourself" and create a single list of inputs, which are actually various versions of the same document in different languages. This question is related to this.
This question is part of a trail of questions. The goal mine was to use this list inside of a tikz
node, but I removed that from this question in the interest of keeping it simple. So, for those interested, here is a quick list for reference:
Related Question for making a macro that can handle post-parsing-inputted list items, see:
For that same solution with tikz
node support, see:
UPDATE 2015-03-08: The following code based on egreg's answer
works 50% of the time
see How can I use a list stored in aux and insert its output into a tikz node?
Situation
I'd like to create a command that has:
- iso 639-1 code as #1
- language name in native tongue as #2
- input file as #3
example: \inputlanguagefile{En}{English}{./Languages/en.tex}
Then I would like to create a list of the language codes from these inputs that can be used in my custom \maketitle
command (warning: \maketitle inputs are sent directly to tikz
nodes)
Problem
The difficulty lies in the fact that the list is called before it is created. I would probably need to create some kind of command to loop through the inputs beforehand. The document would look something like this:
%\maketitle[subtitle]{title}
\maketitle[listoflanguagecodes]{Multilingual Document}
\inputlanguagefile{En}{English}{./Languages/en.tex}
\inputlanguagefile{Da}{Dansk}{./Languages/da.tex}
\inputlanguagefile{De}{Deutsch}{./Languages/de.tex}
\inputlanguagefile{It}{Italiano}{./Languages/it.tex}
\inputlanguagefile{Hu}{Magyarország}{./Languages/hu.tex}
Redefined \maketitle
\maketitle[subtitle]{title} \maketitle[\listoflanguagecodes]{Title}
\renewcommand{\maketitle}[2][]{%
\thispagestyle{empty}
#1\\
#2
\clearpage
\setcounter{page}{1}
}%
The second argument i.e. the actual language names are only used to create a language directory with etoc
.
MWE
I am trying to put together a minimal working example of a complex setup. Work in progress.
autolanglist/
├── Languages
│ ├── da.tex
│ ├── de.tex
│ └── en.tex
└── usermanual.tex
1 directory, 4 files
Contents usermanual.tex
\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage[explicit]{titlesec}
\usepackage{tocloft}
\usepackage{etoc}
\usepackage{lipsum}
\usepackage{hyperref}
\newcounter{runningsectioncounter}
\setcounter{runningsectioncounter}{0}
\titleformat{\section}[hang]{\color{red}\Huge\bfseries}{}{0pt}{\thesection\quad#1}[\stepcounter{runningsectioncounter}]
% Use this \newlangfile{<code>}{<name>}{<file>} to add external language varieties
\newcommand{\inputlanguagefile}[3]{%
\newpage\pdfbookmark{#2}{bkm#1}%
\etoctoccontentsline{part}{#2}%
\setcounter{runningsectioncounter}{\value{section}}
\setcounter{section}{0}
\renewcommand*{\theHsection}{chX.\the\value{runningsectioncounter}} % Keeps hyperref happy (provides unique section numbers instead of using the section counter)
\input{#3}%
}
\renewcommand{\maketitle}[2][]{%
#1\\
#2
\clearpage
}%
\newcommand{\usermanualfrontmatter}{%
\maketitle[En, Da, De]{User Manual} % NOTE: This is the list of language codes should be automated!
\newpage
\setcounter{tocdepth}{0} % make ToC contain only parts
\renewcommand{\contentsname}{Language Directory} % change ToC Title
\tableofcontents
\newpage
\setcounter{tocdepth}{4}
\renewcommand{\contentsname}{Table of Contents} % reset ToC Title back to default
}%
\begin{document}
\usermanualfrontmatter{}
\inputlanguagefile{En}{English}{./Languages/en.tex}
\inputlanguagefile{Da}{Dansk}{./Languages/da.tex}
\inputlanguagefile{De}{Deutsch}{./Languages/de.tex}
\end{document}
Contents of ./Languages/da.tex
\maketitle[da]{Brugsanvisning}
\newpage
\localtableofcontents
\newpage
\section{Test}
\lipsum[50]
Contents of ./Languages/de.tex
\maketitle[de]{Gebrauchsanweisung}
\newpage
\localtableofcontents
\newpage
\section{Test}
\lipsum[50]
Contents of ./Languages/en.tex
\maketitle[en]{User Manual}
\localtableofcontents
\clearpage
\section{Test}
\lipsum[50]
Output
The first page is scaled down A4 paper, but the rest were resized too 100mm x 150mm to save screen real estate on this website :) I attempted to clearly show which list should be generated automatically. The contents of which are not added until later in the document (\inputlanguagefile
).