# Can we make preread replacements in an *.m* file before being run?

This the second question of (152743), the preamble of which is reproduced here:

Those who don't have/prefer the front end of Mathematica will either use a plain ASCII editor to write a script in an .m file or just use Mathematica directly from a command-line terminal. In either case, everything must be supplied in InputForm.

When working with a Mathematica package, commonly used symbols/functions might be excessively verbose in InputForm, and certain shortcuts/aliases would be greatly desired. Examples of built-in InputForm shortcuts are the infix operators + (Plus), - (Minus), ... and . (Dot).

Two questions that arise as a package developer:

1. (152743)

2. Is there something analogous to #define of C and C++ that can be placed at the top of an .m file that instructs the kernel to make replacements of literal occurrences before the lines are read? (this issue may be easily bypassed if question 1 is answered.)

No. In fact, even $PreRead is ignored when reading .m files. What you can do is define a myGet as myGet[file_] := Module[{str}, str = Import[file,"Text"]; str = myTextReplacemeansts[str]; ToExpression[str]; ]  to make your own substitutions. • Dang. OK, I'll wait for others to provide other possible solutions. – QuantumDot Jul 31 '17 at 21:54 • Hmm.. I'm finding that $Pre and $PreRead are not observed when using Mathematica from a command-line terminal. Are $Pre and $PreRead strictly front-end functions? – QuantumDot Aug 1 '17 at 15:11 • It shouldn't be restricted to the FE, but I'm seeing the same behavior. Time to file a bug report... – Itai Seggev Aug 2 '17 at 3:05 • Actually, $Pre is working fine, it's only $PreRead is broken. Are you use $Pre isn't working for you? Try $Pre=Echo. – Itai Seggev Aug 2 '17 at 3:34 • Here is a work around. If you launch the kernel with the -rawterm option, it will fix $PreRead, though that will disable the arrow keys. On Linux (and probably on OSX using homebrew or similar), you can use the rlwrap program as wrapper around the kernel to restore the arrow OKs – Itai Seggev Aug 2 '17 at 3:51