1

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.

siracusa
  • 13,411
  • 2
    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 '19 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 '19 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 '19 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 '19 at 16:38
  • @WeatherReport At first they do seem simpler to type, however there are only so many letters in the alphabet, plust most of them are already taken, leaving you with only a dozen or so. Also most modern editors with LaTeX syntax highlighting know \frac and \epsilon, but not \f and \e. There is also the problem you have just stumbled upon. I just don't recommend doing it. sed is a command line tool for text manipulation. You can do sed -e 's/\\e/\\epsilon/g' <filename> and it will replace all occurrences of \e by \epsilon. – Phelype Oleinik Jun 20 '19 at 18:08
  • 1
    https://tex.stackexchange.com/questions/67709/ – Torbjørn T. Jun 20 '19 at 19:24
  • @PhelypeOleinik I think the regular expression will need to be more complicated, so that you don't end up with \epsilonpsilon. – Teepeemm Jun 21 '19 at 00:27
  • @Teepeemm Oops... One more reason not to use \e instead of \epsilonpsilon :-) – Phelype Oleinik Jun 21 '19 at 02:30
  • @TorbjørnT. Thank you sir! Btw, that question has 40 upvotes and here I'm told that what I want is no good at all. Well, I think I'm gonna stick to my guns! – Weather Report Jun 21 '19 at 07:29

2 Answers2

1

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}.

schtandard
  • 14,892
0

This question had already an answer on stackoverflow which I am reproducing here.

There is this nice Python script that does what you are looking for:

http://www.ctan.org/tex-archive/support/de-macro

lcv
  • 275