# Convert Math in Text Form to $\LaTeX$ Form

I have the following math as a text file:

text = {"aᵢ₁β₁ + aᵢ₂β₂ + ... + aₙ₁βₙ = bᵢ"}


Is it somehow possible to convert it clean $$\LaTeX$$ Input ?

The Goal: I want to convert it to clean $$\LaTeX$$ Input. So I thought, that converting it to Mathematica Input Form and then to $$\LaTeX$$ Input using TeXFormwould maybe do it. What do you think ?

Expected Result:

a_{i1} \beta_{1} + \a_{i2} \beta_{2} + ... + \a_{n1} \beta_{n} = b_{i}


$$a_{i1} \beta_{1} + a_{i2} \beta_{2} + ... + a_{n1} \beta_{n} = b_{i}$$

text = "aᵢ₁β₁ + aᵢ₂β₂ + ... + aₙ₁βₙ = bᵢ";
text2 = StringReplace[text, {"ᵢ" -> "i", "₁" -> "1", "₂" -> "2", "ₙ" -> "n"}];
TeXForm[ToExpression[StringReplace[text2,
{"..." -> "…", a : "a" | "β" | "b" ~~ b : "i" | "n"|DigitCharacter ~~
c : (DigitCharacter ...) :>
StringJoin["Subscript[", a, ",", b, c, "]"]}], StandardForm, HoldForm]]


$$a_{\text{i1}} \beta _1+a_{\text{i2}} \beta _2+\ldots +a_{\text{n1}} \beta _n=b_i$$

• Wow, very nice ! Is there any possibility to automate the StringReplace function, if for instance I also have a gamma in my function ? Could't you use the the unicode hex value of the character which you already extracted ? Have a look here, for instance the small n would not have to be assigned manually: fileformat.info/info/unicode/char/2099/index.htm Commented Oct 16, 2018 at 11:08
• Have a look at my updated question. The "a" is actually an "a" and not an alpha, my mistake. So yes... it would be great if one could "look up" the unicode characters and transcribe them to mathematica standard characters and then to TeXForm Commented Oct 16, 2018 at 11:10
• Maybe using this: reference.wolfram.com/language/ref/ToCharacterCode.html Commented Oct 16, 2018 at 11:52
• I created a new question for that: mathematica.stackexchange.com/questions/184015/… Commented Oct 16, 2018 at 13:11
• @james, i did try to use the character codes to convert "₁" to 1 and "ᵢ" to "i" but that conversion has to be manual because there is no simple relation between character codes of "a" -"z" and those of the corresponding tiny versions.
– kglr
Commented Oct 16, 2018 at 20:14