Define each character as a command in LaTeX

I am working on a large project involving several sets of documents in LaTeX. I want to be consistent in using characters, so it would be nice to define a command for each character that has a specific meaning throughout the project. Does anyone have any experience? Are there any issues that I should pay attention to?

A bit more specific. Say that in the whole document I would designate something called valid with script P, it would be an idea to define

\providecommand{\permeability}{\mathscr{P}} 

or will it be more like the case "command definition for $ n $"?

+4
source share
2 answers

I do this for everything that has a specific meaning and is longer than one character, mainly to save input:

 \newcommand{\objId}{\mbox{$\mathit{objId}$}\xspace} \newcommand{\insOp}[1]{#1\mbox{$^+$}\xspace} \newcommand{\delOp}[1]{#1\mbox{$^-$}\xspace} 

However, then I noticed that I stopped making mismatch errors (objId vs ObjId vs ObjID), so I agree that this is a good idea.

However, I'm not sure if this is a good idea if the characters in the output are Latin characters, for example:

 \newcommand{\numOfObjs}{$n$} 

It is too easy to enter one character and forget about it, even if a command has been defined for it.

EDIT: using your IMHO example, it would be nice to define \permeability , because it is more than one P that you must enter without a command. But this is a close call.

+3
source

A few tips:

  • Using \providecommand will define this command only if it has not been previously defined. Therefore, if you do not get the expected results, perhaps you are trying to identify a team that was defined elsewhere.
  • If you complete the math in your commands using \ensuremath , it will do the right thing regardless of whether you are in math mode when issuing the command:

     \providecommand{\permeability}{\ensuremath{\mathscr{P}}} Now I can easily use \permeability in text or $\permeability$ in math mode. 
  • Using your own commands allows you to easily change the typographic presentation of something later. For instance:

     \newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}} 

    will print \vect{x} as bold x . If you later decide that you prefer arrows over your vectors, you can change the command:

     \newcommand{\vect}[1]{\ensuremath{\vec{#1}}} 
+3
source

Source: https://habr.com/ru/post/1286661/


All Articles