3

Right now, I’m defining a specialized float environment with

\NewDocumentEnvironment{sidebar}{ O{\fps@sidebar} }
   {\edef\reserved@a{\noexpand\@xfloat{sidebar}[#1]}\reserved@a 
     % OTHER STUFF
   }
   {\end@float}

I’m thinking that this is precisely the sort of thing that all the fancy expl3 syntax is meant to simplify, isn’t it? If so, is there a “better”

Updated to add \@xfloat is a LaTeX kernel command (for those who don't have the kernel memorized). The above code is actually similar to how \@float is defined to handle the default case of no optional argument.

5

This looks like a simple x-type case

\use:x { \exp_not:N \@xfloat { sidebar } [ #1 ] }

Ideally you'd make \@xfloat protected, which is more a job for etoolbox

\robustify\@xfloat

to avoid the \exp_not:N too.

1
  • To clarify, \@xfloat is a LaTeX kernel command.
    – Don Hosek
    Mar 17 at 21:06
6

You can make your own version of \@xfloat noting that it requires a second argument in brackets.

\cs_new_protected:Nn \donhosek_xfloat:nn { \@xfloat{#1}[#2] }
\cs_generate_variant:Nn \donhosek_xfloat:nn { nV }

and your \fps@sidebar should actually be a token list variable

\tl_new:Nn \donhosek_sidebar_default_tl

so you can now do

\NewDocumentEnvironment{sidebar}{o}
 {
  \IfNoValueTF { #1 }
   {% no optional argument supplied, use the default
    \donhosek_xfloat:nV { sidebar } \donhosek_sidebar_default_tl
   }
   {% optional argument supplied
    \donhosek_xfloat:nn { sidebar } { #1 }
   }
 }
 { \end@float }

If you need to use \fps@sidebar, then you can assimilate it to a token list variable and the code would be

\cs_new_protected:Nn \donhosek_xfloat:nn { \@xfloat{#1}[#2] }
\cs_generate_variant:Nn \donhosek_xfloat:nn { nV }
\NewDocumentEnvironment{sidebar}{o}
 {
  \IfNoValueTF { #1 }
   {% no optional argument supplied, use the default
    \donhosek_xfloat:nV { sidebar } \fps@sidebar
   }
   {% optional argument supplied
    \donhosek_xfloat:nn { sidebar } { #1 }
   }
 }
 { \end@float }

In case the kernel changes how the optional argument is managed, you can modify the definition of \donhosek_xfloat:nn to take care of this.

This site is temporarily in read only mode and not accepting new answers.

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