2

In an old question Converting LaTeX into Unicode for email it is asked how to look up LaTeX symbols as Unicode. So far the most satisfactory answer is given by @Tom. I followed the link in the answer and found a gadget that does the following thing:

  • Given \alpha\partial\infty it returns α∂∞
  • Given \mathcal{H}\mathbb{R} it returns ℋℝ
  • Given \slash{B}\underline{x}\bar{p} it returns B̸x̲p̅ (combining character)
  • Given e^{1+\phi}_{ρ(χ)} it returns e¹⁺ᵠᵨ₍ᵪ₎ (subscript and superscript)
  • Given \sfrac{1}{2}\sfrac{5}{8} it returns ½⅝ (fraction)

However there are some defects: it cannot handle \overline{AB}, \sfrac12, \mathfrak{F}, \not\exists and some symbols are missing, such as \longrightarrow and \bigcap.

As a comparison, I compile the following code

\documentclass{article}
    \usepackage{unicode-math}
\begin{document}
    $\alpha\partial\infty$
    $\mathcal H\mathbb R\mathfrak F$
    $\slash B\underline x\bar p$
    $e^{1+\phi}_{ρ(χ)}$
    $\frac12\frac58$
    $C\longrightarrow D$
\end{document}

and select-and-copy the pdf file. I get

𝛼𝜕∞HR𝔉/𝐵𝑥𝑝̄𝑒1+𝜙 15 𝐶⟶𝐷 𝜌(𝜒) 28

Notice that Latin and Greek characters are in italic, and \mathfrak works.

I would like to know if there is any method that combines the benefits of the preceding two methods, so that by a^{10}+b^{10}=c^{10} I can get 𝑎¹⁰ + 𝑏¹⁰ = 𝑐¹⁰. (Notice the space.)

Update

@Heiko Oberdiek gives a direction: extend the python code. But I will leave this question open as I suspect that this could be done by pure TeX.

In my personal opinion, the converting mechanism should follow some or all of the following rules.

Spaces

Wikipedia says that there are many types of spaces in Unicode. Perhaps we can choose three and associate them to \thinmuskip, \medmuskip, \thickmuskip.

Or we can preserve all spaces and let users control the spacing. (But there is some trouble: for example a\alpha = 1 and \alpha a = 1 )

Sub & superscript

Nested sub and superscript e^{n^2} should be converted to e^{n²}. That is, only the innermost sub and superscript is converted.

If a subformula contains characters that has not sub or superscript counterpart, do nothing. For example x^{12q}.

Fraction

Fraction \frac12 could be converted to ½ or 1/2. Also \frac{ab}{cd} can be converted to (ab)/(cd) or ab/cd; but \frac{a+b}{c+d} is always (a+b)/(c+d).

Reversibility

I expect that all resulting unicode strings are themselves valid LaTeX code when is included. However, one might prefer x^(p+q) to x^{(p+q)} or x^{p+q}. And x^sin s looks better than x^{\sin s}.

Application

1

The work of the stuff in the link of the question points to an embedded Python script. It takes the arguments of the command line and converts it by textual replacements. If the argument contains spaces, they should be preserved:

a^{10} + b^{10} = c^{10}

(This is also better readable TeX code.)

The script could be extended by pattern replacements like:

    % after line: (ur'\^g', u'\u1D4D'),
    (ur'\s*\+\s*', u' + '),

But, this will quite fast become very complicate (e.g., there are binary and unary minus signs, the latter should not be followed by a space).

  • You are absolutely right; I check the code and realize that it is nothing but iterated string-replacements. – Symbol 1 Oct 22 '16 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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