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
Veak
  • 1

3 Answers3

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.

wipet
  • 74,238
  • 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. – Ulrike Fischer Oct 07 '22 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:-) – David Carlisle Oct 07 '22 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 07 '22 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. – Ulrike Fischer Oct 07 '22 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 08 '22 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.

JamesT
  • 3,169
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
David Carlisle
  • 757,742
  • If this solution is not recommended, would \newIf not be better because one knows it is not the language convention. – Veak Oct 08 '22 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. – David Carlisle Oct 08 '22 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 08 '22 at 20:01