On 12/14/2021 6:16 PM, Benjamin Buchmuller via ntg-context wrote:
Hi!

I'd like to follow up on a problem that Denis came across recently with the titles 
argument in tabulate. (It's more a solution than a question, but any hints to improve the 
answer are welcome.) I wanted to use this argument for an easy specification of, well, a 
title for a "recipe". The advantage is that all information is held together 
and it's easy to use for people who are not (too) familiar with ConTeXt.

So, in one file I can define all styles (which the end-user would not need to 
see):

\definetabulate[recipe][|l|l|p|l|]

\setuptabulate
        [recipe]
        [
        bodyfont=small,
        distance=medium,
        before={\blank[back, small]},
        header=text,
        headstyle=\bi, % this formats the "\BC" cells
        headcolor=red, % this formats the "\BC" cells
        ]


\starttext

And then use:

\startrecipe[title={Whatever mixture 1}]
\FL
\NC Absolute \BC Stock \NC Ingredient \NC Final \NR
\HL
\NC 1 \NR
\LL
\stoprecipe

\startrecipe[title={Whatever mixture 2}]
\FL
\BC Absolute \BC Stock \BC Ingredient \BC Final \NR
\HL
\NC 1 \NR
\LL
\stoprecipe

\stoptext

etc.

However, I cannot change the way the title is styled (or spaced from the table) unless I 
do "title={\bi Some text.}". However, blank commands are also stripped off at 
this place. (I also don't get a clue from the source if there is any argument to spike-in 
some formatting.)

So, if there is no easy way to access this one, we can work around:

\definetabulate[recipetab][|l|l|p|l|]

\setuptabulate
        [recipetab]
        [
        bodyfont=small,
        distance=medium,
        before={\blank[back, small]},
        % header=text, % THIS MUST NOT BE "text"
        headstyle=bold,
        headcolor=red,
        ]

\define\startrecipe{\dodoubleempty\dostartrecipe}

\long\def\dostartrecipe[#1][#2]#3\stoprecipe{%
        \iffirstargument
                {\bi #1}\blank[medium]
        \fi
        \ifsecondargument
                \startrecipetab[#2]
                #3
                \stoprecipetab
        \else
                \startrecipetab
                #3
                \stoprecipetab
        \fi
}

\startrecipe[Head 1]
\FL
\BC Absolute \BC Stock \BC Ingredient \BC Final \NR
\HL
\NC 1 \NR
\LL
\stoprecipe

\startrecipe[Head 2][headcolor=blue] % pass on arguments to tabulate
\FL
\BC Absolute \BC Stock \BC Ingredient \BC Final \NR
\HL
\NC 1 \NR
\LL
\stoprecipe

Small question though: Is there a ConTeXt way to "\long\def" or a simple way ("user 
interface") to filter a list of arguments for a specific key=val pair, e.g. to make a single 
optional argument with headertitle={Some header.}?
context has no (need for) \long ... all is long (i mever saw a reason for using it)

(1) use a proper head:

\definehead[RecipeHead][subsubsubsubsubsubject]
\setuphead [RecipeHead][style=bolditalic,after={\blank[medium]}]

\definetabulate[recipetab][|l|l|p|l|]

\setuptabulate
  [recipetab]
  [bodyfont=small,
   distance=medium,
   before={\blank[back, small]},
   headstyle=bold,
   headcolor=red]

here's a one-step lmtx solution:

\let\stoprecipe\relax

\tolerant\protected\def\startrecipe[#1]#*[#2]#3\stoprecipe
  {\ifcstok{#1}\emptytoks\else
     \RecipeHead{#1}
   \fi
   \ifcstok{#2}\emptytoks
     \startrecipetab#3\stoprecipetab
   \else
     \startrecipetab[#2]#3\stoprecipetab
   \fi}

or just

\tolerant\protected\def\startrecipe[#1]#*[#2]#3\stoprecipe
  {\ifempty{#1}\else
     \RecipeHead{#1}
   \fi
   \ifempty{#2}%
     \startrecipetab#3\stoprecipetab
   \else
     \startrecipetab[#2]#3\stoprecipetab
   \fi}


and here's one that does what you ask (in the core i'd try to avoid grabbing too much arguments and if real core we'd make sure dummy parameters don;t interfere):

\tolerant\protected\def\startrecipe[#1]#2\stoprecipe
  {\ifempty{#1}%
     \startrecipetab#2\stoprecipetab
   \orelse\ifhastok={#1}%
     \getdummyparameters[headtitle=,#1]
     \ifempty{\dummyparameter{headtitle}}\else
       \normalexpanded{\RecipeHead{\dummyparameter{headtitle}}}
     \fi
     \startrecipetab[#1]#2\stoprecipetab
   \else
     \RecipeHead{#1}
     \startrecipetab#2\stoprecipetab
   \fi}

\startrecipe[headtitle={Head 3},headcolor=blue] % pass on arguments to tabulate
\FL
\BC Absolute \BC Stock \BC Ingredient \BC Final \NR
\HL
\NC 1 \NR
\LL
\stoprecipe

Here's a variant:

\def\theparameter#1#2%
  {\beginlocalcontrol
   \begingroup
   \getdummyparameters[#1=,#2]%
   \normalexpanded{\endgroup\endlocalcontrol\dummyparameter{#1}}}

\tolerant\protected\def\startrecipe[#1]#2\stoprecipe
  {\ifempty{#1}%
     \startrecipetab#2\stoprecipetab
   \orelse\ifhastok={#1}%
     \edef\MyHeadTitle{\theparameter{headtitle}{#1}}%
     \ifempty\MyHeadTitle\else
       \normalexpanded{\RecipeHead{\MyHeadTitle}}
     \fi
     \startrecipetab[#1]#2\stoprecipetab
   \else
     \RecipeHead{#1}
     \startrecipetab#2\stoprecipetab
   \fi}

or just

\tolerant\protected\def\startrecipe[#1]#2\stoprecipe
  {\ifempty{#1}%
     \startrecipetab#2\stoprecipetab
   \else
     \edef\MyHeadTitle{\theparameter{headtitle}{#1}}%
     \ifempty\MyHeadTitle\else
       \normalexpanded{\RecipeHead{\MyHeadTitle}}
     \fi
     \startrecipetab[#1]#2\stoprecipetab
   \fi}

or

\tolerant\protected\def\startrecipe[#1]#2\stoprecipe
  {\ifempty{#1}%
     \startrecipetab#2\stoprecipetab
   \else
     \ifcstok{\theparameter{headtitle}{#1}}\emptytoks\else
       \normalexpanded{\RecipeHead{\theparameter{headtitle}{#1}}}
     \fi
     \startrecipetab[#1]#2\stoprecipetab
   \fi}

or ... or ... or ...

just play with it a bit till you have something that looks nice in code too

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

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

Reply via email to