I am working on the construction of a music package and I would like to have new commands with short names for clarity... So for example I use \bar, \k, \arg but they are already defined in LaTeX Is there some trick so that all these commands could be used at least locally with the way I like?

In other words, Is it possible to define some special commands inside my package let say \mypackageONand \mypackageOFF so that if I encolse a text with the above start-end commands no broblem will arise with the use of \bar etc? Is there a better strategy? Excuse me for this general question...

  • 4
    You could provide an environment called, say, mypackage which redefines \arg, \bar, etc. That way, the scope of the redefinitions ends with \end{mypackage}.
    – Mico
    Feb 15, 2016 at 7:15
  • 3
    You could look e.g. at siunitx where all unit definitions are "active" only inside the \si/\Si-commands. Feb 15, 2016 at 8:35
  • @Ulrike Fisher Do you know how these commands si and Si are defined? How one could avoid a conflict using a command like\si{a long text with my coomands.....} There must a mechanism for activation and diactivation!
    – kornaros
    Feb 15, 2016 at 14:39
  • 1
    @kornaros -- Have a look at the user guide of the siunitx package to learn how \si and \SI are defined. :-)
    – Mico
    Feb 15, 2016 at 14:41
  • @Mico I have already looked. I don't find where \si is defined. This package has 101 pages. I just want to have some idea how si is defined so that it could accept any new definition without the risk of name clashes! Thanks for your interest!
    – kornaros
    Feb 15, 2016 at 15:57

1 Answer 1


You could provide an environment called, say, myenv, which redefines \arg, \bar, etc. That way, the scope of the redefinitions automatically ends with \end{myenv}.

A simple working example:

\usepackage[T1]{fontenc} % Enable "\k" ("ogonek") macro

   % Provide (re)definitions of \arg, \bar, etc

$\arg a$, $\bar{b}$, \k{c}

\arg a, \bar{b}, \k{c}

$\arg a$, $\bar{b}$, \k{c}

Here's a version that uses "switches" -- named \mypackageON and \mypackageOFF -- instead of an environment. As per the suggestion made by Ulrike in a comment, the code first saves the original versions of \arg, \bar etc, and the new macros are given "music" prefixes. Then, \mypackageON activates the music-related versions of the macros, and \mypackageOFF activates the original versions of the macros. (\LetLtxMacro is used instead of \let, just in case some of the commands being redefined take optional arguments and/or were declared to be "robust".)

enter image description here

\usepackage[T1]{fontenc} % Enable "\k" macro ("ogonek")

% Save the old versions of the macros
\usepackage{letltxmacro} % for "\LetLtxMacro" command

% Define some new macros
\newcommand\musicarg[1]{#1} % "#1" just regurgitates the argumenet

\newcommand\mypackageON{% enable the music-related versions

\newcommand\mypackageOFF{% enable the original versions

$\arg a$, $\bar{b}$, \k{c}

\arg a, \bar{b}, \k{c}

$\arg a$, $\bar{b}$, \k{c}
  • The idea is very good. But the only problem is when I use a lot of \begin{myenv} \end{myenv} Is it better to make a switch like \mypackageON and \mypackageOFF where in the first case I save the commands to other names .eg. \argoriginal and in the other command I redefine the arg command using \argoriginal? What is your opinion?
    – kornaros
    Feb 15, 2016 at 14:28
  • @kornaros - I think it would be helpful if you gave some specific examples of what the redefined macros \arg, \bar, etc are supposed to achieve. (Warning: Sadly, I know exceedingly little about musicological notation.)
    – Mico
    Feb 15, 2016 at 14:41
  • These commands are very simple indeed. For axample, \bar calls a symbol from a specific font using the command \char" + hex number. I do not like to change this name to someting like \musicbar or similar. because bar is a very common music term! The use of the enviroments has only one danger like \begin{myenv} \begin{myenv} \end{myenv} Because of the nested myenv if one forget the last \end{myenv} then the he will have a problem. So I suggest that it is beter to use "switchers" like \mypackageON and \mypackageOFF. Is it good idea, or it is better to use an enviroment?
    – kornaros
    Feb 15, 2016 at 15:33
  • @kornaros: He would also have a problem if he forgets \mypackageOFF and unlike with environment there would be perhaps no warning. Beside this: I wouldn't use \def in the environment, but outside do something like \newcommand\myspecialarg{...} and inside \let\arg\myspecialarg. Feb 15, 2016 at 16:39
  • @UlrikeFischer I think you are right! It is better to let the LaTeX do the ckeck for us! Thanks!
    – kornaros
    Feb 15, 2016 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .