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}$


1 Answer 1

text = "aᵢ₁β₁ + aᵢ₂β₂ + ... + aₙ₁βₙ = bᵢ";
text2 = StringReplace[text, {"ᵢ" -> "i", "₁" -> "1", "₂" -> "2", "ₙ" -> "n"}];
   {"..." -> "…", 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$

  • $\begingroup$ 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 $\endgroup$
    – james
    Commented Oct 16, 2018 at 11:08
  • $\begingroup$ 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 $\endgroup$
    – james
    Commented Oct 16, 2018 at 11:10
  • $\begingroup$ Maybe using this: reference.wolfram.com/language/ref/ToCharacterCode.html $\endgroup$
    – james
    Commented Oct 16, 2018 at 11:52
  • $\begingroup$ I created a new question for that: mathematica.stackexchange.com/questions/184015/… $\endgroup$
    – james
    Commented Oct 16, 2018 at 13:11
  • $\begingroup$ @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. $\endgroup$
    – kglr
    Commented Oct 16, 2018 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.