TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an ever growing preamble and it contains commands like \su and \so for the special unitary and special orthogonal group algebra, just \mathfrak{SU}. Then later I wanted to use the soul package to strike out some text. Its command is \so for strikeout. Both abbreviations do make sense and when I tried lo load soul, I got an error, of course.

In programming languages there are often namespaces (Python, C++) but then my commands would have to be much longer and would be a pain to type.

Is there any other way to prevent this beforehand? Or is that a fundamendal difficulty with LaTeX?

share|improve this question
4  
That is not a LaTeX problem. You can put a label called egg on an apple and similar label on a peach. Now, it either is random, the last tagged item or the warning/error that you cannot label different things with the same tag. Or define the same command twice. – Johannes_B Jan 15 at 8:34
4  
The usual problem is 'lazyness' -- We don't want to type long commands, but most package commands are short in name, the likelihood to have a name clash is quite large, especially for compounds like strike-out. Even if it is annoying or tedious: Use longer names for your 'abbrevations' – Christian Hupfer Jan 15 at 8:49
1  
Or at least, use particular wordings: if \su exists, then change it to \mysu. Usually adding my helps. For example, \circ is an existing command, but \mycirc is fair territory. – Alenanno Jan 15 at 10:23
    
@Alenanno my is an often used but fairly strange prefix i think. It is the same for your documents, as well as for mine, because the def is ours. How about using the name initials? Like JB for my name or LT as used with longtable. – Johannes_B Jan 15 at 18:14
    
@Johannes_B Well, either is fine, as long as you are reasonably sure that it's not going to break anything. Initials are not always a sure choice, because your initials might be coincidentally be the same of a command/package. :D – Alenanno Jan 15 at 18:15

For internal package names many packages have a pseudo namespacing scheme of prefixing commands with a (hopefully) unique prefix, so longtable internals are all \LT@..., tabularx internals are all \TX@...

For packages using expl3 conventions the internal prefixing is more formalised and there is a register of prefix names to avoid clashes.

https://github.com/latex3/latex3/blob/master/l3kernel/l3prefixes.csv

At the top level you could do that (without the non-letter-separator) so for example longtable has some lengths starting \LT without an @ \LTpre but mostly you just don't do that and "grab" some usefully short name.

There are usually fewer top level commands and it is easier to alias them: if two packages define \foo it is often (not always:-) enough to use something like

\usepackage{pkga}
\let\fooa\foo
\let\foo\undefined
\usepackage{pkgb}
\let\foob\foo

So that you have both functionalities available but under the names \fooa and \foob.

Again the programming model underlying expl3 tries to formalise this, the idea is that you have your functionality written using prefixed names and expl3 syntax conventions but then one or more top level user interface commands can be defined using xparse that call the underlying code, so if you need a different name you should at most have to change the xparse declaration, all the main functionality should be in uniquely prefixed package code.

share|improve this answer
3  
Perhaps also note that in a single document it would be tricky (at least) to use \foo for two different meanings other than within rather restricted contexts (e.g. in siunitx I use \pm for 'picometre' in units). – Joseph Wright Jan 15 at 8:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.