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?
2 Answers
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.
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.
\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.\large
,\Large
and\LARGE
.