I have start looking at the package cals, so my examples are connected to that packages. However, my questions are general, applicable under other environments, too.

In the documentation (this TUGboat article) the author has defined a handy macro to switch on and off colour in cells:

\def\c{\ifx\cals@bgcolor\empty      % Colour switch (on of)
\else \def\cals@bgcolor{} \fi}

It seems that a prerequisite for this macro, is that cals@bgcolor{} is defined. If not defined, the first instance you use the macro, you have to execute it twice before it works as I expected (turning on the defined colour).

How do I extend the macro to test for both an undefined(?) and an empty value?

The macro is used before and after a cell, or a range of cells (and/or rows):


It switch on colour for cell G, turn colour off for cell H, on for cell I and off before the next row.

I managed to extent the macro to switch off and on cell borders:

\def\bb{\ifx\cals@borderB\relax     % Border switch (on of)
\else \let\cals@borderB\relax\fi}

and padding:

\def\rp{\ifdim\cals@paddingR=0.0pt\relax    % Right padding switch (off-on)
\else \setlength{\cals@paddingR}{0pt}\fi}

I tried to implement the same solution for bold (to turn on and off bold or other attributes, on a cell). However, I was not able to find how to test if \bfseries already was set.

\def\b{\ifx\<bold>\<false>  % Is \bfseries on or off?
     \bfseries              % If its off, turn it on
\else \mdseries\fi}         % If its on, turn it off

How do I write this macro to test if bold on, and if the condition is false, turn bold on. If the conditions is true, \mdseries should be turned on?

  • For the first part of the question: use \ifdefined. The second part I do not understand. – user121799 May 31 at 0:18
  • @marmot See my updated question. Is in more understandable what I want to achieve? – Sveinung May 31 at 7:31
  • 1
    \c is already defined, the redefinition breaks ç, \b is also defined. Never use \def like this. – Ulrike Fischer May 31 at 7:43
  • @UlrikeFischer I use at least two letters "in real life". The \c-macro comes from the cals documentation. However, the ideas behind shortcuts is to reduce the number of keystrokes. – Sveinung May 31 at 19:45

The current font series is stored in \f@series, you can test if it contains a b (which would mean bold):


  \tl_if_in:cnTF { f@series } {b}


blblblb \switchbold bold \switchbold not bold

enter image description here

  • You mention both, \f@size and \f@series. Was it an intention or am I completely wrong? – Marian G. May 31 at 8:45
  • @MarianG. that was a typo, thanks. – Ulrike Fischer May 31 at 8:49

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.