2

Is there an established expl3 way of working with insertions defined in TeX? The issue came up for me with trying to modify \footins. I don't see anything in the documentation other than the renamed TeX primitives.

I've started to roll my own functions, as illustrated in the MWE below, but what I have so far is definitely not suitable for generic use and will break if given the wrong input.

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\cs_new:Npn \insert_to_int:N #1 {\tex_count:D #1 \scan_stop:}
\cs_new:Npn \insert_to_dim:N #1 {\tex_dimen:D #1 \scan_stop:}
\cs_new:Npn \insert_to_skip:N #1 {\tex_skip:D #1 \scan_stop:}

\cs_new_protected:Npn \insert_set_int:Nn #1#2 {\tex_count:D #1 \int_eval:n {#2}}
\cs_new_protected:Npn \insert_set_dim:Nn #1#2 {\tex_dimen:D #1 \dim_eval:n {#2}}
\cs_new_protected:Npn \insert_set_skip:Nn #1#2 {\tex_skip:D #1 \skip_eval:n {#2}}

\NewDocumentCommand{\dumpvals}{}
{
  Magnification~factor~--~before:~\int_use:N \insert_to_int:N \footins

  \insert_set_int:Nn \footins {2 * \insert_to_int:N \footins}~

  after:~\int_use:N \insert_to_int:N \footins\par

  Maximum~insertion~size~--~before:~\dim_use:N \insert_to_dim:N \footins

  \insert_set_dim:Nn \footins {-100pt + \insert_to_dim:N \footins}~

  after:~\dim_use:N \insert_to_dim:N \footins\par

  Extra~space~--~before:~\skip_use:N \insert_to_skip:N \footins

  \insert_set_skip:Nn \footins {6pt plus 1pt minus .5pt + \insert_to_skip:N \footins}~

  after:~\skip_use:N \insert_to_skip:N \footins\par
}
\ExplSyntaxOff

\begin{document}
  \dumpvals
\end{document}
1

1 Answer 1

1

The package referenced by Yiannis employed the trick of using \cs_new... to create aliases for the tex sequences \count\footins, etc. and giving them conventional expl3 variable names. For example:

\cs_new:Npn \g_test_footins_box  {\footins}
\cs_new:Npn \g_test_footins_int  {\tex_count:D\footins}
\cs_new:Npn \g_test_footins_dim  {\tex_dimen:D\footins}
\cs_new:Npn \g_test_footins_skip {\tex_skip:D\footins}

I generalized this to arbitrary inserts, but obviously production code should have if-exists tests to check for problems:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\cs_new_protected:Npn \test_insert_init:N #1
{
  \cs_new:cpn {g_test_ \cs_to_str:N #1 _box}  {#1}
  \cs_new:cpn {g_test_ \cs_to_str:N #1 _int}  {\tex_count:D #1}
  \cs_new:cpn {g_test_ \cs_to_str:N #1 _dim}  {\tex_dimen:D #1}
  \cs_new:cpn {g_test_ \cs_to_str:N #1 _skip} {\tex_skip:D #1}
}

\test_insert_init:N \footins

\NewDocumentCommand{\dumpvals}{}
{
  Magnification~factor~--~before:~\int_use:N \g_test_footins_int

  \int_gset:Nn \g_test_footins_int {2 * \g_test_footins_int}~

  after:~\int_use:N \g_test_footins_int\par

  Maximum~insertion~size~--~before:~\dim_use:N \g_test_footins_dim

  \dim_gset:Nn \g_test_footins_dim {\g_test_footins_dim / 2}~

  after:~\dim_use:N \g_test_footins_dim\par

  Extra~space~--~before:~\skip_use:N \g_test_footins_skip

  \skip_gset:Nn \g_test_footins_skip {\g_test_footins_skip + 6pt plus 1pt minus .5pt}~

  after:~\skip_use:N \g_test_footins_skip\par
}
\ExplSyntaxOff

\begin{document}
  \dumpvals
\end{document}

You must log in to answer this question.

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