0

In the MWE below, how can I reset the value of the title key, assigned to \l__lecture_title_tl, so that the third instance of \lecture doesn't print A title?

\documentclass{article}

\usepackage{lipsum}
\usepackage{xparse}

\ExplSyntaxOn

\keys_define:nn { lecture-notes } {
  title .tl_set:N = \l__lecture_title_tl,
}

\NewDocumentCommand{ \lecture }{ O{} }{
  \keys_set:nn { lecture-notes } { #1 }

  \tl_set:Nn \l__section_title_tl {
    \tl_if_empty:NF \l__lecture_title_tl { \l__lecture_title_tl }
  }

  \section{\l__section_title_tl}
}

\ExplSyntaxOff

\begin{document}

\lecture
\lipsum[1]

\lecture[title={A title}]
\lipsum[2]

\lecture % <-- this still prints 'A title'
\lipsum[3]

\end{document}

enter image description here

1
  • If I enclose the definition of the \lecture command in \group_begin: ... \group_end:, the vertical spacing between the sections is affected, and the following text is indented.
    – noibe
    Oct 6, 2020 at 16:45

1 Answer 1

1

Given your definition of \lecture, you get \keys_set:nn { lecture-notes } {} when the optional argument is not used, so naturally no keys are reset. Instead, you want to pass title={}. So you need \NewDocumentCommand{ \lecture }{ O{title={}} }{....

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .