5

Having been exploring expl3 I have been updating some of my code to it, and I ran into a interesting issue that I was not predicting.

I get a strange error that I think is from trying to store multiple paragraphs into a sequence. I didnt find anything in the interface3 manual, does anyone know of an way around this?

I put my old method and new trail method for variable storage below for those who are interested.

Here is my old code.

\newcommand{\@supernote}{}
\newcommand{\supernote}[1]{\renewcommand\@supernote{#1}}

And here is my new code.

\seq_new:N \itemsupernote
\NewDocumentCommand{\supernote}{sm} {
    \seq_put_right:Nn \itemsupernote {#2}
}

Calling the function works the same way for both

\supernote{Here is my example

and here is the other half}

Here is my error for the new method in case it helps.

runaway argument? {here is my example Paragraph ended before \supernote was omplete.
<to be read again> \par l.109 
  • What's the s-type argument for here? – Joseph Wright Feb 5 '16 at 22:55
  • @JosephWright May be to easily expand the command in the future? I tend to add so to certain macros that might need \foo* or even \foo[..] just to make it easy in the future. – Manuel Feb 5 '16 at 22:57
  • @Manuel They're both optional and the point of xparse is that the interface isn't tied to the internals, so adding them later should be trivial anyway. – Joseph Wright Feb 5 '16 at 22:58
  • @JosephWright I mean just to avoid typing in the future (I answered because you could see similar code in my .tex, I don't know Bob's reason). \NewDocumentCommand \foo { s o m } { \bob_foo:n { #3 } } just so I don't have to change #1 to #3 in the future. Pure laziness, at least on my side. – Manuel Feb 5 '16 at 23:00
8

The issue is not with the code layer (which is all 'long'), but with your interface set up. As the more common case for document commands is that they should only take short pieces of text, xparse creates 'short' commands as-standard. To make an argument 'long' you need to mark it as such with a +

\NewDocumentCommand \supernote { s +m }
  {
    \seq_put_right:Nn \itemsupernote {#2}
  }

Notice that xparse deals with long/short arguments on an argument-by-argument basis rather than switching all of them in one go.

  • Aside: the sequence really should be called something like \l_bob_note_seq – Joseph Wright Feb 5 '16 at 22:51
  • How come you don't have to specify that with the old \newcommand? As for the variable name thing, I thought you said (in another question of mine) that all variables are actually global? – Bob Feb 6 '16 at 3:06
  • @Bob \newcommand is 'long' as standard and you have to use \newcommand* to be more restrictive. (Lamport only provided \newcommand, the current LaTeX team added the starred form in 1994 but couldn't change the existing behaviour). – Joseph Wright Feb 6 '16 at 6:31
  • @Bob Variable are declared globally, but that's not the same as set globally. If your variable is meant to be set globally use \seq_gput_right:Nn and call it something like \g_bob_note_seq. – Joseph Wright Feb 6 '16 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.