Context
The current question arises:
- as an attempt to improve the aim explained in a question of mine (Expl3' tl variable storing the result of a \seq_map_inline: OK in article's title but not in beamer's title),
- in order to explain why using
\exp_not:N
instead of\exp_not:V
, as suggested by egreg in his answer of another question of mine (\TeX and \LaTeX differently expl3-x-written (exhaustive expansion) to an auxiliary file), is useless in my use case.
Aim (sum up)
I have a main (beamer
) document, say main.tex
, the content of which varying,
depending on the targeted audience. For this, main.tex
inputs one or more of,
say, 5 slave files: topic1.tex
, topic2.tex
, topic3.tex
, topic4.tex
,
topic5.tex
.
Each topic (file) has a topic title and I want the title of the main document to automatically be the list of the titles of the topics that are input (and only the ones that are input).
For this, I used the following strategy:
- At the beginning of each topic file, the topic title is specified, thanks to
a
\topictitle
macro. - Each time it is used, this macro appends the corresponding topic title to the
right of a
\g_topics_seq
sequence. - At the end of the (main) document:
- the content of
\g_topics_seq
sequence is placed in a\g_presentation_title_tl
token list, - the (not expanded:
\exp_not:V
) content of\g_presentation_title_tl
isx
-written to an auxiliary.sbj
file.
- the content of
- At the end of the preamble of the (main) document (hence at the next
compilation):
- a scratch token list is
x
-set to contain the content of the auxiliary file, - the content of this scratch token list is passed to
\title
.
- a scratch token list is
The following MCE is the implementation of this strategy but I wonder if expl3
could provide a better one.
\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\usepackage[check-declarations]{expl3}
\usepackage{xparse}
\begin{filecontents*}{topic1}
\topictitle{% \TeX{},
\LaTeX{} and café%
}
\begin{frame}
\TeX{}, \LaTeX{} and café are nice!
\end{frame}
\end{filecontents*}
\begin{filecontents*}{topic2}
\topictitle{Topic 2}
\begin{frame}
Topic 2 is nice!
\end{frame}
\end{filecontents*}
\begin{filecontents*}{topic3}
\topictitle{Topic 3}
\begin{frame}
Topic 3 is nice!
\end{frame}
\end{filecontents*}
\begin{filecontents*}{topic4}
\topictitle{Topic 4}
\begin{frame}
Topic 4 is nice!
\end{frame}
\end{filecontents*}
\begin{filecontents*}{topic5}
\topictitle{Topic 5}
\begin{frame}
Topic 5 is nice!
\end{frame}
\end{filecontents*}
\ExplSyntaxOn
\seq_new:N \g_topics_seq
\tl_new:N \g_presentation_title_tl
\iow_new:N \g_output_stream
\NewDocumentCommand{\topictitle}{m}
{
\__topic_title:n {#1}
}
\cs_new_protected:Npn \__topic_title:n #1
{
\seq_gput_right:Nn \g_topics_seq {#1}
}
\AtEndDocument
{
\tl_gset:Nx \g_presentation_title_tl
{
\seq_use:Nn\g_topics_seq {,~}
}
\iow_open:Nn \g_output_stream { \c_sys_jobname_str.sbj }
\iow_now:Nx \g_output_stream { \exp_not:V\g_presentation_title_tl }
\iow_close:N \g_output_stream
}
\AtEndPreamble{%
\file_if_exist:nTF {\c_sys_jobname_str.sbj} {
\tl_set:Nx \l_tmpa_tl {\file_input:n {\c_sys_jobname_str.sbj}}
\exp_args:NV \title \l_tmpa_tl
}{
\title{No topic!}
}
}
\ExplSyntaxOff
\begin{document}
\maketitle{}
%
\input{topic1}
% \input{topic2}
\input{topic3}
% \input{topic4}
\input{topic5}
\end{document}
.aux
file, it was empty (I probably didn't read it at the right moment). IIRC, I also had some difficulties to write both a verbatim text (e.g.\title{
and}
) and, inside, the (not expanded:\exp_not:V
) content of\g_presentation_title_tl
. – Denis Bitouzé May 10 '19 at 15:05.aux
file: it is automatically\input
as part of the work done by\begin{document}
, before the\AtBeginDocument
hooks are run. – frougon May 10 '19 at 15:17