Replace all shorthands defined by \newcommand with full commands

I'm used to using my own shorthands while typesetting papers, say I use

\newcommand{\f}{\frac}
\newcommand{\e}{\epsilon}


Recently it became important to me to make my source files readable for other people, so this shorthands are undesirable. Is there any way to replace all occurrences of shorhands defined by \newcommand by the full name? For example

\lim_{\e\to0} \f{\sin{\e}}{\e}=0


should be replaced by

\lim_{\epsilon\to0} \frac{\sin{\epsilon}}{\epsilon}=0


So I could type with my usual shorhands, but could also easily make a copy of my source file with all shorthands expanded.

• You shouldn't make those "shorthands" to begin with. In the long run they will become longer hands (pun intended) than you'd wish for. At the TeX level is complicated to do that. Perhaps some smart sed substitutions will help you. – Phelype Oleinik Jun 20 at 15:53
• you can obviously write some script for perl or python or your editor to make the replacements, tex can not really help as there is no distinction, to latex, from a user defined macro such as \e to a latex defined macro such as \section or \documentclass – David Carlisle Jun 20 at 16:02
• @PhelypeOleinik what is the problem with newcommands? I don't know what sed is, but if you have to be smart to use it this is probably not the solution I'm looking for. – Weather Report Jun 20 at 16:36
• @DavidCarlisle Sure, that should be an easy script. I'm just checking whether this is not already done and say integrated in some editor. – Weather Report Jun 20 at 16:38

This is not really a TeX question, so no TeX here. The easiest thing is probably to just use regular expressions (any good text editor will support them). For example, you could use \\f(?![a-zA-Z]) to find all occurrences of \f and replace those with \\frac (or \frac, depending on the editor and preferences). If you have any \makeatletter in your document and you are sure that you never wrote \f@ where you meant \frac@ (why would you..?), it's safer to use \\f(?![a-zA-Z@]) instead.

This will of course not detect things like \csname f\endcsname or \@nameuse{f}.