GeneralVariable naming

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
stretch65
Posts: 4
Joined: Thu Mar 18, 2010 6:49 am

Variable naming

Post by stretch65 »

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Variable naming

Post by josephwright »

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":

Code: Select all

\newdimen\si@unt@powerdim
\newif\ifsi@unt@per
\newif\ifsi@unt@perseen
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:

Code: Select all

\def\macro{%
  \localdimen\mylocaldimen % I've made up this function!
  ...
}
and have \mylocaldimen only available within \macro.
Joseph Wright
Post Reply