# Translate in-line equations to TeX code (Any Package?)

I have a software that allows to implement equations and one can write them in-line such as:

==================

x = a_avg + ((x-1)/b_trans)^(-y^(-x))

y = ....

z = .... (something that have a similar form)

... etc, etc

=================


So basically, I have a *.doc full of these equations and I would like to translate them to Latex, so that they would look like this:

$x = a_{avg} + \frac{x-1}{b_{trans}}^{-y^{-x}}$


The challenge comes from translation of indexes (e.g. avg, trans) to {} for the subscript or superscript. Also translate ()/() to \frac{}{}. Is anyone aware of such a package that would translate the entire document into list of equations? Or does anyone have any idea how can one do this?

Paul

• you'd want b_{\mathrm{trans}} (never typeset multi-letter words in math italic) a simple regex replace of _([a-z]*) to _{\\mathrm{\1}} should work in any editor. – David Carlisle Sep 30 '16 at 11:28
• Thank you David. But I would like to translate the entire document. Not equation by equation. – Physther Sep 30 '16 at 11:32
• sure but you just apply the same replace globally just as if you change "yes" to "no" it's as easy to change one as all instances in a document – David Carlisle Sep 30 '16 at 11:33
• Did you see the posting Expanding subscript and subscript capabilities? – Mico Sep 30 '16 at 11:35
• Please see my much improved answer. – Steven B. Segletes Apr 21 '17 at 19:35

if eq.txt contains lines like

x = a_avg + ((x-1)/b_trans)^(-y^(-x))


then a simple edit line such as

 sed -e 's/(/{(/g' -e 's/)/)}/g'  -e 's/\//\\over /g' -e 's/_$$[a-z]*$$/_{\\mathrm{\1}}/g' -e 's/.*/$\0$/' eq.txt


will output

$x = a_{\mathrm{avg}} + {({(x-1)}\over b_{\mathrm{trans}})}^{(-y^{(-x)})}$


for each line

which when typeset as

\documentclass{article}

\begin{document}

$x = a_{\mathrm{avg}} + {({(x-1)}\over b_{\mathrm{trans}})}^{(-y^{(-x)})}$

\end{document}


produces

I used sed here but you could use perl or lua or your editor search/replace.

Actually you need to work a bit harder with the regex on the brackets (note one ) slipped down... ) but this is I hope enough to show the basic idea.

• the parentheses around the fraction are totally misplaced. of course, here they aren't necessary, and are even harmful as shown. – barbara beeton Sep 30 '16 at 11:49
• @barbarabeeton a minor detail:-) – David Carlisle Sep 30 '16 at 11:52
• Great! I tried and it worked! Thank you so much. I have two more questions. How to replace "" with "\cdot", I added on the "sed" command this: 's/*/\cdot', but it didn't work. I guess the "" symbol is confusing. It says "unknown option to 's' And the second one, is it possible to add a $$before every line and$$ after each equation (each other line?) – Physther Sep 30 '16 at 12:02
$\interpreteq{f(x) = y^(2*x) =beta}$
$\interpreteq{f(x) = pi * y^[((2/x)^3 + [B/x_i])^n] =(z/B)^(2/x_i)}$
$\interpreteq{f(x) = pi * y^[((2/x)^3 + B/x_i )^n] =(z/B)^(2/x_i)}$
$\interpreteq{x = a_avg + ([x-1] /b_trans)^(-y^[-x])}$

This is the code DNA'' that expresses the above equation:

\detokenize\expandafter{\Z}% COPY/PASTE RESULT OF THIS FROM PDF TO BELOW

See?  I copied/pasted it into equation mode and get the same result.
$\Q [1,1,1,1,1,1,1]\QS [1]\Q [2,1,1,1,1,1,1]\QS [2,1,1,1,1,1]\Q [2,1,1,1,1,2,1]\QS [2,1,1,1,1]\Q [2,1,1,1,2,1,1]\QS [2,1]\Q [2,2,1,1,1,1,1]\QS [2,2]\Q [2,3,1,1,1,1,1]\QS [2,3,1,1,1]\Q [2,3,1,1,2,1,1]\QS [2,3]\Q [2,4,1,1,1,1,1]\QS [2,4,1,1]\Q [2,4,1,2,1,1,1]\QS [2,4,1,2,1,1]\Q [2,4,1,2,1,2,1]\QS [2,4]\Q [2,5,1,1,1,1,1]\QS [2,5,1]\Q [2,5,2,1,1,1,1]\QS [2,5]\Q [2,6,1,1,1,1,1]\QS [2,6,1,1,1]\Q [2,6,1,1,2,1,1]\QS [2,6,1]\Q [2,6,2,1,1,1,1]\QS [2,6]\Q [2,7,1,1,1,1,1]\QS [2,7,1,1,1]\Q [2,7,1,1,2,1,1]\QS [2,7]\Q [2,8,1,1,1,1,1]\QS [2,8]\Q [2,9,1,1,1,1,1]$

\textbf{TRANSLATING EQUATIONS}
\begin{translateeqs}% NO BLANK LINE IS PERMITTED HERE
cos(1/s) = f*g

f(x) = y^(2*x) =beta

f(x) = pi * y^[((2/x)^3 + [B/x_i])^n] =(z/B)^(2/x_i)

f(x) = pi * y^[((2/x)^3 +  B/x_i )^n] =(z/B)^(2/x_i)

x = a_avg + ([x-1] /b_trans)^(-y^[-x])
\end{translateeqs}% NO BLANK LINE IS PERMITTED BEFORE HERE

\translateeq{x = a_avg + ([x-1] /b_trans)^(-y^[-x])}

\end{document}


• (+1) but ... why? – cfr Sep 30 '16 at 23:16
• @cfr Well, if I managed to write the nested loop that could fully automate the process, it would allow one to \input equations composed in a different format and present them in the standard LaTeX way. – Steven B. Segletes Sep 30 '16 at 23:21
• @cfr See my edit (for the 2nd time) to really see what I had in mind from the beginning – Steven B. Segletes Apr 18 '17 at 17:14
• Now it makes more sense - thanks for the explanation. Can't upvote again, sadly. – cfr Apr 18 '17 at 18:09
• @HenriMenke Thanks, It still could be a challenge to fully support ASCII math, but I will have a look, when I get a chance. – Steven B. Segletes Aug 8 '20 at 23:22