0

I need to prevent commands from reprocessing a parameter. Is there the way to exit command before end if condition is met just like return in JavaScript functions:

function calculateSomething(param) {
  if (!param) {
    return  // <---- leave the function
  }

// go on with the function }

So in LaTeX I imagine something like this:

\newcommand{\mycommand}[1] {

\ifthenelse{\equal{#1}{what I want}} { %%%exit%%% <--- stop processing and out } { \color{red}{#1} } }

Arek
  • 29
  • There is no such thing in latex. You can do an if statement, but you cannot "return" and ignore what comes after the if statement (if I'm reading your question correctly). You'll need to cyan things over several macros. – daleif Aug 28 '22 at 08:49
  • 1
    Your ifthenelse does what you want, it doesn't process the color command. So what is your problem with it? – Ulrike Fischer Aug 28 '22 at 09:20
  • @UlrikeFischer warning that something went wrong... For example – Arek Aug 28 '22 at 10:19
  • 1
    well you can add warnings in one of the branches. – Ulrike Fischer Aug 28 '22 at 10:24
  • 3
    macros are not functions you do not return from a local scope as you would with a function call, they are textual replacement, the whole of the definition is placed online in the input stream if you want to skip some of it you need a conditional in the replacement text, you can not return to the original state – David Carlisle Aug 28 '22 at 14:08

1 Answers1

2

Thank you for your response. The solution is to define options to be unique - thus executing all code does not cause an error.

\newcommand{\marker}[3][] {

\ifthenelse{\equal{#2}{todo} \and \equal{\statustodo}{show}}{{\color{blue}#3}}{} \ifthenelse{\equal{#2}{todo} \and \equal{\statustodo}{hide}}{#1}{} \ifthenelse{\equal{#2}{todo} \and \equal{\statustodo}{mask}}{#3}{}

\ifthenelse{\equal{#2}{deprecated} \and \equal{\statusdeprecated}{show}}{{\color{red}#3}}{} \ifthenelse{\equal{#2}{deprecated} \and \equal{\statusdeprecated}{hide}}{#1}{} \ifthenelse{\equal{#2}{deprecated} \and \equal{\statusdeprecated}{mask}}{#3}{} }

It's workaround, but it works. Thanks and have a good day :-)

Arek
  • 29
  • This is not that easy to understand, and harder to understand how this relates to your original question. At some point, you need to explain what you're trying to do. – Teepeemm Aug 28 '22 at 21:06