0

I would like to turn this answer into an environment. Therefore, I use xparse to define a LaTeX3 environment, but I am missing a little something because it creates errors.

It seems, I have issues about delimiters and end of environments.

In here a MWE:

\documentclass{article}

  \usepackage{graphicx,float}
  \usepackage{amsmath}
  \usepackage{paracol}
     \setlength{\columnseprule}{0.4pt}
     \setlength{\columnsep}{2em}

  \usepackage{xparse}
     \ExplSyntaxOn
     \NewDocumentEnvironment{outParaCol}{+b}
     {
        \group_begin:
        \switchcolumn[0]*[#1]
     }
     {
        \group_end:
     }
     \ExplSyntaxOff


\begin{document} 

\begin{paracol}{2}
  \begin{leftcolumn}
     For several days in succession fragments of a defeated army had passed through the town. 
     
     They were mere disorganized bands, not disciplined forces. 
     The men wore long, dirty beards and tattered uniforms; they advanced in listless fashion, without a flag, without a leader.
     All seemed exhausted, worn out, incapable of thought or resolve, marching onward merely by force of habit, and dropping to the ground with fatigue the moment they halted.
  \end{leftcolumn}
  \begin{rightcolumn}
     Pendant plusieurs jours de suite des lambeaux d'armée en déroute avaient traversé la ville. 

     Ce n'était point de la troupe, mais des hordes débandées. 
     Les hommes avaient la barbe longue et sale, des uniformes en guenilles, et ils avançaient d'une allure molle, 
     sans drapeau, sans régiment. Tous semblaient accablés, éreintés, incapables d'une pensée ou d'une résolution,   marchant seulement par habitude, et tombant de fatigue sitôt qu'ils s'arrêtaient. 
  \end{rightcolumn}

  \begin{outParaCol} % not working %  Missing delimiter (. inserted). <to be read again> \tex_par:D 
  % \switchcolumn[0]*[{ % working
     \begin{equation}
           a+B \left[\frac{1}{2}\right]
     \end{equation}
  % }] % end of switchcolumn
  \end{outParaCol}

  \begin{outParaCol} % not working % Paragraph ended before \@float@HH was complete. <to be read again> \par 
  % \switchcolumn[0]*[{ % working
     \begin{figure}[H]
     \centering
     \includegraphics[width=\linewidth]{example-image}
     \setlength{\columnwidth}{\dimexpr 0.5\textwidth-0.5\columnsep}%
        \caption{A caption}
     \end{figure}
  %  }] % end of switchcolumn
  \end{outParaCol}

  \begin{leftcolumn}
     One saw, in particular, many enlisted men, pea\-ceful citizens, men who lived quietly on their income, bending beneath the weight of their rifles; and little active volunteers,   easily frightened but full of enthusiasm, as eager to attack as they were ready to take to flight; and amid these, a sprinkling of red-breeched soldiers,       the pitiful remnant of a division cut down in a great battle; somber artillerymen, side by side with nondescript foot-soldiers; and, here and there, the gleaming helmet of a heavy-footed dragoon who had difficulty in keeping up with the quicker pace of the soldiers of the line.
  \end{leftcolumn}
  \begin{rightcolumn}
     On voyait surtout des mobilisés, gens pacifiques, rentiers tranquilles, pliant sous le poids du fusil; des petits moblots alertes, faciles à l'épouvante et prom\-pts à l'enthousiasme, prêts à l'attaque comme à la fuite; puis, au milieu d'eux, quelques culottes rouges, débris d'une division moulue dans une gran\-de bataille; des artilleurs sombres alignés avec des fantassins divers; et, parfois, le casque brillant d'un dragon au pied pesant qui suivait avec peine la marche plus légère des lignards.
  \end{rightcolumn}

\end{paracol}
\end{document}
%EoF
5
  • 2
    you only need xparse in old latex releases. you have omitted the {} group used in the [{...}] argument in the referenced code Apr 20 at 21:04
  • I tried with \group_begin: ... \group_end: but forgot the simple {}, a bit daft...
    – R. N
    Apr 20 at 21:12
  • you don't need a tex group just delimit an argument, so it has to to be {} you can not use \group_begin, \bgroup, \begingroup etc Apr 20 at 21:16
  • If you want to detail it into an answer, I will accept it. And I would be glad to have more information about this differentiation between tex group and delimiters :)
    – R. N
    Apr 20 at 21:26
  • 1
    By the way, \ExplSyntaxOn and \ExplSyntaxOff aren't needed. Just do \NewDocumentEnvironment{outParaCol}{+b}{\switchcolumn[0]*[{#1}]}{}
    – egreg
    Apr 20 at 21:56

1 Answer 1

3

Note you only need xparse in old latex releases.

\NewDocumentEnvironment is defined (in ltcmd.dtx) as part of the LaTeX format and usable without any package.

The problem is that you have omitted the {} used in the [{...}] argument in the referenced code.

The {} here are delimiting an argument (hiding any nested ] so the optional argument ends where needed). You can not use implicit groups such as \bgroup or \group_begin: for such a use. Just as you need {} in \fbox{abc} you can not use \fbox\bgroup abc\egroup.

You must log in to answer this question.

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