Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

deparse latex code

62 views
Skip to first unread message

greenux

unread,
Oct 29, 2012, 6:27:22 PM10/29/12
to
Hi,
I have the following problem, maybe someone has a simple solution, as I couldn't find a simple or working one.

I have a package which produces (easiest example) from
\symX{abc}{2}
the same code as
X_{abc}^{2}

Now, I'm not allowed to use this package in the final latex source version. Therefore I would like to create a "deparsed" version. I thought about exporting the code "\symX{abc}{2}" to a file and an (expanded?) version "X_{abc}^{2}" too and afterwards use a simple perl script to replace the real code by its expanded version in the tex file. Using an environment around the real code would be OK.
So something like:
\begin{deparse}
\symX{abc}{2} %any kind of code
\end{deparse}

I tried the moreverb package using verbatimwrite, but never got an expanded version of the code, only the original code.

Does anyone has an idea how to create the two output files, one with the original code
"1: \symX{abc}{2}"
and one with the expanded code
"1: X_{abc}^{2}"
, where the number in front is a counter to find corresponding entires in case the lines differ in the two tex files?

thx in advance,
greenux

GL

unread,
Oct 30, 2012, 4:07:47 AM10/30/12
to
Le 29/10/2012 23:27, greenux a écrit :
> Hi,
> I have the following problem, maybe someone has a simple solution, as I couldn't find a simple or working one.
>
> I have a package which produces (easiest example) from
> \symX{abc}{2}
> the same code as
> X_{abc}^{2}
>
> Now, I'm not allowed to use this package in the final latex source version. Therefore I would like to create a "deparsed" version. I thought about exporting the code "\symX{abc}{2}" to a file and an (expanded?) version "X_{abc}^{2}" too and afterwards use a simple perl script to replace the real code by its expanded version in the tex file. Using an environment around the real code would be OK.

Usually, a text editor provides a find/replace dialog with the ability
to use regular expressions.

but if you love pearl oysters scripts, it's your right after all ;-)

greenux

unread,
Oct 30, 2012, 5:05:11 AM10/30/12
to
the problem is that it is not possible to define a regexp, because e.g. the meaning of \symX is also a command so you don't know in advance what to replace.
it is necessary to export the original code and the expanded code to replace each other automatically!

Robin Fairbairns

unread,
Oct 30, 2012, 5:21:54 AM10/30/12
to
i don't think i understand that.

how does
<input> --> regex munger --> <output>
(where "regex munger" is a script that replaces \symX{x}{y} with the
super/subscripted text you showed) not meet your requirements?
--
Robin Fairbairns, Cambridge
sorry about all this posting. i'll go back to sleep in a bit.

greenux

unread,
Oct 30, 2012, 6:59:56 AM10/30/12
to
OK, my fault. The example is maybe to simple. It would be too complex to use regexp, as the result it not always X_{a}^{b} it could also be \sqrt{x}^{a,b} using the same command \symX{a}{b} because if a and b are subscript or superscript depends on another command \scripta and \scriptb which is used.

I may try another question: How can I export any kind of latex code in its original form and its expanded form (without new self-defined commands)?

Thx,
greenux

Axel Berger

unread,
Oct 31, 2012, 7:39:13 AM10/31/12
to
greenux wrote:
> Now, I'm not allowed to use this package in the final latex source
> version. Therefore I would like to create a "deparsed" version.

I don't know what you're using, but for me this would be a typical job
for the editor. One editor script of mine does far more complicated
stuff in translating automatically generated TeX code to HTML. A simple
RegEx replace suffices in your case.

Axel

Robin Fairbairns

unread,
Oct 31, 2012, 7:48:43 AM10/31/12
to
don't know about simple -- greenux was (aiui) merely showing us an
example. (though the example, as you say, would succumb to a rather
simple regex.)

fwiw, the uk faq is written in (slightly constrained) latex, and is
translated (using a perl file containing a rather large bunch of
regexes) to html. in current usage, this happens on the fly in the cgi
code that handles www.tex.ac.uk/faq

GL

unread,
Oct 31, 2012, 8:50:13 AM10/31/12
to
Le 31/10/2012 12:48, Robin Fairbairns a �crit :
> Axel Berger <Axel....@Gmx.De> writes:
>
>> greenux wrote:
>>> Now, I'm not allowed to use this package in the final latex source
>>> version. Therefore I would like to create a "deparsed" version.
>>
>> I don't know what you're using, but for me this would be a typical job
>> for the editor. One editor script of mine does far more complicated
>> stuff in translating automatically generated TeX code to HTML. A simple
>> RegEx replace suffices in your case.
>
> don't know about simple -- greenux was (aiui) merely showing us an
> example. (though the example, as you say, would succumb to a rather
> simple regex.)
>
> fwiw, the uk faq is written in (slightly constrained) latex, and is
> translated (using a perl file containing a rather large bunch of
> regexes) to html. in current usage, this happens on the fly in the cgi
> code that handles www.tex.ac.uk/faq
>
Interesting.
By the way TeX is also able to translate anything to HTML, if properly
set up. It just writes its output to an \openout file.

Such a use of the TeX engine is obviously not LaTeX. But if the source
is /extremely standardized/ it should be possible to produce pdf or html
output, with no extra script.

i say that because i used TeX this way, and it is able for example to
produce HTML tables in a {tabular} (-like) environment...

Cheers.
0 new messages