denis.ma...@unibe.ch schrieb am 12.09.2023 um 23:32:

You need a box to get the author on a separate line.

% \define[2]\ChapterCommand
%   {\vbox
%      {\structureuservariable{author}
%      \blank
%      #1\space#2}}

\starttexdefinition protected ChapterCommand #1#2
   \vbox\bgroup
     \structureuservariable{author}
     \blank
     #1\space#2
   \egroup
\stoptexdefinition

Thank you so much, Wolfgang!

Why do you need protected here? I’ve realized that \protected\def also helps a bit, but, of course, paragraph breaks are ignored there as well…

You probably haven't noticed it yet but unlike the other predefined layouts for sections you don't have to write "alternative=command" to use the layout which is passed to the command key.

To make this work ConTeXt has to check whether the argument of the command key is empty or not but this is problematic when you pass commands with arguments.

When you try to example below you can see that the first definition of \Mycommand fails because \edef\CheckMycommand tries to expand its argument which causes problems because \Mycommand tries to read the following argument. To solve this problem you can use the \protected modifier when you create \Mycommand.

\starttext

\def\Mycommand#1{#1}% fails
%\protected\def\Mycommand#1{#1}% works

\edef\CheckMycommand{\Mycommand}
\ifempty\CheckMycommand
   \tex{Mycommand} is empty
\else
   \tex{Mycommand} has content
\fi

\stoptext


If just found the following in the lowlevel-macros manual:

«Traditional TEX has three prefixes that can be used with macros: \global, \outer and \long. The last two are no-op's in LuaMetaTEX and if you want to know what they do (did) you can look it up in the TEXbook.»

So, \long is gone, but why is that? Is there a new mechanism that serves the same purpose? Other than using a vbox, I mean…

The purpose of the \long modifier is to specify whether the argument of a command can or cannot contain multiple paragraph (either by an empty line or with \par). This was needed by TeX in the early days where memory was limited but not on the current machines.

For a very long time ConTeXt made each command definition long by default (i.e. \def\...{...} behaved the same way as \long\def\...{...}) and as a result \long was dropped.

\def\CommandA#1{#1}

\long\def\CommandB#1{#1}

\starttext

\CommandA{xxx}% works

\CommandA{xxx

yyy}% fails because you have a empty line in the argument

\CommandA{xxx\par yyy}%fails because you have \par in the argument

\CommandB{xxx\par yyy}% works because \CommandB is \long

\stoptext

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

Reply via email to