3

In latex, one commonly uses CamelCase.

In my style file' I have

\newif\ifMath
\Mathfalse

Could these boolean flags be made to allow CamelCase, so the usage is

\newif\ifMath
\MathFalse
8
  • 2
    \let\Mathfalse\MathFalse?
    – JamesT
    Oct 7, 2022 at 18:15
  • You could do this but I would not. You could use expl3 booleans or other forms but if using primitive \if... you should follow the language conventions and use ...true and ...false to save confusing anyone looking at the code Oct 7, 2022 at 18:56
  • @JamesT sorry can you undelete Oct 7, 2022 at 19:17
  • @DavidCarlisle I undeleted. If you had a minute, could you go on meta and give some advice on how newbies could get better please
    – JamesT
    Oct 7, 2022 at 19:20
  • 1
    @JamesT not being confused by wrong advice from old-timers would be a good start:-) Oct 7, 2022 at 19:21

3 Answers 3

4

You can define your own \NewIf macro:

\def\sdef#1{\expandafter\def\csname#1\endcsname}
\def\NewIf #1{\expandafter\NewIfA \string#1\relax #1}
\expandafter\def \expandafter\NewIfA \string \If#1\relax #2{%
   \sdef{#1True}{\let#2=\iftrue}%
   \sdef{#1False}{\let#2=\iffalse}%
   \let#2=\iffalse
}

%test:

\NewIf\IfMath

\IfMath Yes\else No\fi

\MathTrue
\IfMath Yes\else No\fi

\MathFalse
\IfMath Yes\else No\fi

This macro allows you to use CamelCased \IfSomething too. The code above is inspired from \newif macro defined in OpTeX.

5
  • it looks odd imho. If one use CamelCase for the first part, then one should use \Else and \Fi too. Beside this, in LaTeX I would prefer \IfMathTF{true}{false}, that is more consistent with the language. Oct 7, 2022 at 19:04
  • +1 I'd wondered if IfMath would be wanted rather than ifMath, this is obviously more general than mine that doesn't define a definition form (you could define \Else and \Fi for @UlrikeFischer:-) Oct 7, 2022 at 19:06
  • @UlrikeFischer I agree with you but \IfMathTF was not the subject of the question. And if someone want to use \Else, \Fi then \let\Else=\else, \let\Fi=\fi is the solution. But I understand this question: TeX primitives and standard macros are lowercased and newly defined macros should be CamelCased for more explicit differences. Maybe this is the reason why OP needs such soulution.
    – wipet
    Oct 7, 2022 at 19:15
  • @wipet sorry if I sounded as if tried to critizise your solution, That wasn't the intention, I was actually critizising the goal of the question. Oct 7, 2022 at 19:19
  • It would be acceptable to start in lowercase, but the rest use uppercase. The intention is to distinguish between the various parts. Thusly \else is as readable as \Else. And \ifMath is as readable as \IfMath. Starting with uppercase is then not required. Whilst \MathTrue would be more readable than \Mathtrue.
    – Veak
    Oct 8, 2022 at 18:42
3

To answer this question so the community bot doesn't bump every few months hopefully, if you want to assign a macro or value to be the same as another value or macro, use \let, as this answer by Norman Gray explains.

Simply going \let\MathFalse\Mathfalse should assign the value of \Mathfalse to \MathFalse. If you put this at the start of your style file then you should be able to use CamelCase throughout the rest of the .sty file by using \MathFalse in lieu of \Mathfalse.

0
2

you could do this but it breaks the language conventions so it is not a good idea:

Do not use \newif, simply do

\def\MathTrue{\let\ifMath\iftrue}
\def\MathFalse{\let\ifMath\iffalse}
\MathFalse
3
  • If this solution is not recommended, would \newIf not be better because one knows it is not the language convention.
    – Veak
    Oct 8, 2022 at 19:36
  • @konmi I don't think I understand your comment. If you only have one or two of these it doesn't seem worth defining custom definition command, but it doesn't hurt. But I'd use a standard \newif with lowercase true and false. Oct 8, 2022 at 19:50
  • I could call it \galexIf so one knows it is a style setting. This will be defined in a style file galex.sty. Which will be used in documents using the style file.
    – Veak
    Oct 8, 2022 at 20:01

You must log in to answer this question.

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