I recently wrote a module that extracts my Perl code from a LyX document. (LyX is a WYSIWYG LaTeX editor, if that helps provide some context.) Originally I wrote it as a source filter that was meant to be invoked on the command line, as
perl -MyX my-document.lyx
(Yes, the module is called yX.pm.) However, it'd be really cool if I could just type
perl my-document.lyx
Perl is pretty flexible, and I thought that maybe I could get away with throwing a few garbage lines at it before getting to the source filter usage line. So, I tried adding something to the LaTeX preamble, resulting in the following sort of stuff at the beginning of the .lyx file:
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 474
\begin_document
\begin_header
\textclass article
\begin_preamble
%ignore; use yX;
...
Unfortunately, perl is not quite liberal enough:
Number found where operator expected at test.lyx line 2, near "lyxform
+at 474"
(Do you need to predeclare lyxformat?)
Backslash found where operator expected at test.lyx line 3, near "\"
(Missing semicolon on previous line?)
Backslash found where operator expected at test.lyx line 4, near "begi
+n_document
\"
(Missing semicolon on previous line?)
Backslash found where operator expected at test.lyx line 5, near "begi
+n_header
\"
(Missing semicolon on previous line?)
Operator or semicolon missing before %ignore at test.lyx line 7.
Ambiguous use of % resolved as operator % at test.lyx line 7.
syntax error at test.lyx line 2, near "lyxformat 474"
BEGIN not safe after errors--compilation aborted at test.lyx line 7.
The astute observer will notice the very top line begins with a hash character. Furthermore, LyX does not examine the content of this line, so I can change it to something like this:
#!perl -MyX
Unfortunately, Perl does not let you specify a module in the #! line. :-(
Then I struck upon
this discussion of the problem on the Perl Porters mailing list.
Ric's solution is to use the -d switch, which would look like this:
#!perl -d:MyX
Lo! it works (after renaming the module, of course)!
So my question: If I manage to create a module/extension for LyX that adds this shebang line, would I be a horrible person for exploiting this sort of hack?