Hi,
Maybe I'm worrying unnecessarily, but it concerns me that all latex variables names that I can define are global and have the potential to clash with the hundreds (or thousands) of other names found in the myriad of packages that can be used.
And, it annoys me somewhat that latex variables can only be defined using some combination of only upper or lowercase letters. Is there some convention or way that I can choose my names so that they are fairly unlikely to clash with all the other names? I wish so much that I could include an underscore or some other character just so that I can distinguish my names from every other name.
Any help or advice would be appreciated. Thanks.
General ⇒ Variable naming
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Variable naming
You don't say which type of variable you're concerned about. TeX has no formal namespacing, and so the normal convention is to use "@" as a divider. Most packages use a few letters at the start of every variable and macro name to avoid clashes. For example, my siunitx package uses "si":
In a document, you'd need to surround this with \makeatletter ... \makeatother, as "@" cannot normally be used in csnames.
One thing the LaTeX3 Project is looking at is trying to make things a bit more formalised in this area. For example, we're currently looking at local variables, but the limitation is that TeX doesn't allow you to do something like:
and have \mylocaldimen only available within \macro.
Code: Select all
\newdimen\si@unt@powerdim
\newif\ifsi@unt@per
\newif\ifsi@unt@perseen
One thing the LaTeX3 Project is looking at is trying to make things a bit more formalised in this area. For example, we're currently looking at local variables, but the limitation is that TeX doesn't allow you to do something like:
Code: Select all
\def\macro{%
\localdimen\mylocaldimen % I've made up this function!
...
}
Joseph Wright