TransWikia.com

How to expand rightmark?

TeX - LaTeX Asked by facetus on December 23, 2020

I am puzzled why I cannot expand rightmark to pass to another macro. Consider the following mwe

documentclass[12pt, twoside, letterpaper]{scrartcl}

usepackage{scrlayer-scrpage}

renewcommand*{sectionmark}[1]{markright{item1,item2}}
ExplSyntaxOn
lohead{%
    {%
        exp_args:NNV seq_set_from_clist:Nn l_seq_sec_parts rightmark%
        seq_item:Nn l_seq_sec_parts {1}%
    }}
rohead{}
ExplSyntaxOff

begin{document}

section{Some section}

end{document}

This code sets rightmark to a comma separated list using sectionmark. Then, while setting up a left odd page heading, the code tries to retrieve the first item of the list. First, it calls seq_set_from_clist:Nn to convert the list into a sequence, then seq_item:Nn returns the first item of the sequence.

exp_args:NNV is supposed to fully expand rightmark and pass the expansion as an argument to seq_set_from_clist:Nn.

I expect to see item1 in the heading. However, it doesn’t happen. item1,item2 is printed instead, which means rightmark wasn’t expanded. How to fix it?

One Answer

If I add cs_show:N rightmark to your lohead code, I get

> rightmark=macro:->expandafter @rightmark firstmark @empty @empty .

With exp_args:NNV you don't fully expand the third argument, but just get its first level expansion with a pair of braces around.

You need to expand rightmark in order to arrive at the comma separated list, but not expanding “too much”, because fragile commands might break the construction.

documentclass[12pt, twoside, letterpaper]{scrartcl}

usepackage{scrlayer-scrpage}

renewcommand*{sectionmark}[1]{markright{item1,item2}}
ExplSyntaxOn
cs_generate_variant:Nn clist_item:nn { e }
lohead
 {
  clist_item:en { text_expand:n { rightmark } } { 1 }
 }
rohead{}
ExplSyntaxOff

begin{document}

section{Some section}

end{document}

However, this might break if fragile commands are used in the marks. For this you can u

Correct answer by egreg on December 23, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP