0

In Latex's commands, I see that all the commands are in lowercase? This is very difficult to distinguish the words? Why don't we use CamelCase? Is there a reason for that?

7
  • 7
    Your observation is wrong. There are \Phi and the like in title case and \DeclareRobustCommand etc. in camel case. It's very dependent on the subset of LaTeX you use whether you encounter these, though.
    – TeXnician
    Commented Mar 22, 2022 at 9:10
  • 5
    lowercase is easier to type, so most user commands stick to it. Camel case is used for package commands. Commented Mar 22, 2022 at 9:17
  • Yes, thank you so much! Commented Mar 22, 2022 at 9:17
  • 1
    tex.stackexchange.com/a/48207/1090 Commented Mar 22, 2022 at 9:22
  • 2
    We don't. Very often it does not matter, so we stick to the lower case commands, but sometimes it does: cf. \large, \Large and \LARGE.
    – Ingmar
    Commented Mar 22, 2022 at 9:37

2 Answers 2

12

Most LaTeX document commands are lowercase, though this is not universal: in the core there are things like \Phi, as pointed out in comments, but there are also packages which add some mixed or uppercase commands. Probably the most obvious mixed-case command is \LaTeX itself! However, one might say that the pattern for document commands is as you say that they are lowercase other than where there is a direct semantic meaning to uppercasing some of the characters: the commands for Greek/Russian uppercase characters, logos, etc.

Design/package commands tend to be CamelCase. This makes them 'stand out' as being aimed primarily at package authors. For example, in a package one might see \ProvidesPackage or \DeclareRobustCommand, etc. These would not normally be common in a document.

There are a very limited number of all-uppercase commands. The most obvious to me is \SI from my siunitx package, but there are others. In general, all-uppercase tends to be avoided. This makes names in this area useful for example for debugging: the LaTeX team often use \ERROR as a place-holder when creating error conditions, for example.

2
  • Personally, I normally use camelCase for identifiers that start with a lowercase letter, and call commands such as \DeclareRobustCommand, PascalCase.
    – Davislor
    Commented Mar 22, 2022 at 14:47
  • Is \DocumentMetadata considered to be a "design/package command"? Why?
    – memeplex
    Commented Mar 9 at 19:51
5

It’s an arbitrary convention, but it’s important to be consistent. If Donald E. Knuth had sometimes used lowercase, sometimes camelCase, sometimes PascalCase, for TeX primitives, it would’ve been much harder to remember whether the command is \baselineskip, \baselineSkip or \BaselineSkip, or maybe \BaseLineSkip. The few exceptions in the original design are very logical, such as \Theta being a capital \theta and \TeX matching the typography of the logo. Leslie Lamport also originally stuck to this for LaTeX (with the exception previously mentioned, \LaTeX, following the example of \TeX).

Most newer LaTeX kernel commands in fact follow a different convention, either \PascalCase or \scope_snake_case_type:xyz for anything in expl3 syntax. So, \newcommand, but \DeclareRobustcommand, and you just have to remember whether any given command is older or newer than the change. Here, it helps to remember that \Declare commanda are almost always newer. With things like \IfFileExists, well, they couldn’t very well have clashed with the TeX primitive \if, could they? But with commands like \providecommand and \ProvidesPackage, you just have to memorize them case by case. Some other packages (such as ucharclasses) use \camelCase, and this has bitten me more than once. You might or might not agree with this decision, but at least if you know which module the command is from and which convention it uses, you can keep it straight.

1
  • Thank you for explanation! ! 1 up vote. Commented Mar 22, 2022 at 15:50

You must log in to answer this question.

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