2

I do not know if the Latex code (which is auto-generated is invalid) or if pdflatex is supposed to be able to handle this code, but I need to find the correct package. I looked at this entering-unicode-characters-in-latex and added the package mentioned there. But still get the error. May be I need to define a macro? Do I need to add a smart \DeclareUnicodeCharacter to handle this? Is there a way to use this \DeclareUnicodeCharacter to make these unicodes below which are causing the problem to be just a single white space so that pdflatex and latex can process the file?

Mathematica generates Latex code for one of its expression which uses special Mathematical symbols (small dot above and below letters) as shown in this link

Here is a screen shot from my notebook showing the Latex code generated

Mathematica graphics

When I use this Latex code in my document, pdflatex.exe actually crashed (MikTex) and also texlive on Linux gave the error:

(/usr/local/texlive/2014/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsfonts/umsb.fd)
! Undefined control sequence.
l.11 ...to \text{DifferentialRoot}\left(\{\unicode
                                                  {f818},\unicode{f817}\}
? 

The code generated is complicated and I can't edit it by hand, else I will break the Latex code generated if I start moving parts around (I also need to run this many times, so need a one time fix)

Here is a MWE on one actual case. I have many such cases, so looking for a macro I can put at top of the Latex document that solves all these \unicode problems. A solution that removes all those unicodes is just fine as well. The symbols do not have to have those dots above or below, but this is how Mathematica generates them. But for the pdf file, I do not need them really.

\documentclass[12pt]{article}
\usepackage{amsmath,mathtools}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[mathletters]{ucs}
\usepackage[utf8]{inputenc} 
\begin{document}

$\left\{\left\{y(x)\to \text{DifferentialRoot}\left(\{\unicode{f818},
  \unicode{f817}\}
  \unicode{f4a1}\left\{\left(a^2 \unicode{f817}^3+a\right) 
  \unicode{f818}(\unicode{f817})+\left(2 \unicode{f817}^3 a-1\right) 
  \unicode{f818}'(\unicode{f817})+\unicode{f817} 
  \unicode{f818}''(\unicode{f817})=0,
  \unicode{f818}(1)=c_1,\unicode{f818}'(1)=c_2\right\}\right)(x)\right\}\right\}$

\end{document} 
Nasser
  • 20,220
  • 1
    When talking about unicode one has to mention XeTeX and LuaTeX, unicode aware engines. \par But then f818 <- Have a look at the emphasised text. – Johannes_B Jul 22 '14 at 07:15
  • @Johannes_B I am just set up to use texlive, and on windows I use miktex default setup. I really never used XeTex or LuaTex and do not know how to set them up now. I just need a simple solution to handle these unicodes. Even replacing them with space will work for me. I just do not know how to do this. I also use tex4ht, and want to keep the same setup as is. – Nasser Jul 22 '14 at 07:18
  • \documentclass{article} \newcommand{\unicode}[1]{} \begin{document} $\unicode{f817} \unicode{f4a1} \unicode{f818}$ \end{document} – Johannes_B Jul 22 '14 at 07:26
  • @Johannes_B thanks, but this gives an error Double superscript Mathematica graphics ! Double superscript. l.37724 ...code{f4a1}\left\{\left(a^2 \unicode{ }^ 3+a\right) \unicode{ }(\un...? – Nasser Jul 22 '14 at 07:31
  • You should better put somewhere for download a small file which shows your original problem for instead of showing an example of a non-working solution. – Ulrike Fischer Jul 22 '14 at 07:32
  • @UlrikeFischer I do not follow. I have put a MWE which shows the problem? I copied the code from my large file where the error is and made a MWE that just includes the lines that causes the error. I added some packages at the top to see it will help. But feel free to remove those if they are not needed. – Nasser Jul 22 '14 at 07:34
  • 1
    As the unicode char is gone with my definition, a double superscript stays. use \newcommand{\unicode}[1]{\begingroup{ \endgroup} instead. But to be honest, i don't see the point in doing so. The error will disappear, but the whole meaning will drop dead. Not a good idea, imho. – Johannes_B Jul 22 '14 at 07:39
  • 2
    Can't you setup Mathematica to outout the unicode glyphs directly? – Johannes_B Jul 22 '14 at 07:39
  • I looks as if I missunderstood your description. You mean the complete example -- starting from \documentclass to \end{document}-- was autogenerated? You didn't change anything? Well pdflatex shouldn't crash on this (and it doesn't for me) unless there is something additional in the original file. So you should show this file. – Ulrike Fischer Jul 22 '14 at 07:47
  • @UlrikeFischer I use autogenerated Latex code from Mathematica and Maple. This auto-generated Latex code is read into a main latex document from text files. I just add the headers and the packages at the top. So the code itself in the example was auto-generated. pdflatex on windows does crash, here is a screen shot Mathematica graphics – Nasser Jul 22 '14 at 07:58
  • I didn't doubt that you get a crash. But to investigate the reason one needs to be able to reproduce the crash and for this one needs the actual files. Too much can be changed when you copy&paste content to a website. – Ulrike Fischer Jul 22 '14 at 08:03
  • @Nasser I don't understand why the solution which ignores the dots above and below the x, y letters was choosen as accepted. My solution solves these dots, direcly separates the added part and the autogenerated part. But my name isn't egreg... – wipet Jul 22 '14 at 17:10
  • @wipet I've up-voted your answer and wish I could accept both answers. But I did say A solution that removes all those unicodes is just fine as well. The symbols do not have to have those dots above or below and I just happened to try the first answer first before you posted yours and it worked, then I saw your answer after that. I wish the rules allows one to accept more than one answer. Thanks again for your help and time. – Nasser Jul 22 '14 at 18:14

2 Answers2

5

U+F817, U+F818 and U+F4A1 point to the private use area, so it's impossible to say what they should produce, because it's font dependent.

Looking at your picture, the correspondence seems to be

  • U+F817 is x
  • U+F818 is y
  • U+F4A1 is ,

So you can do

\makeatletter
\newcommand{\unicode}[1]{\@nameuse{unicode@#1}}
\newcommand{\unidef}[2]{\@namedef{unicode@#1}{#2}}
\makeatother

\unidef{f817}{x}
\unidef{f818}{y}
\unidef{f4a1}{,}

Complete code:

\documentclass[12pt]{article}
\usepackage{amsmath,mathtools}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}

\makeatletter
\newcommand{\unicode}[1]{\@nameuse{unicode@#1}}
\newcommand{\unidef}[2]{\@namedef{unicode@#1}{#2}}
\makeatother

\unidef{f817}{x}
\unidef{f818}{y}
\unidef{f4a1}{,}

\begin{document}

$\left\{\left\{y(x)\to \text{DifferentialRoot}\left(\{\unicode{f818},
  \unicode{f817}\}
  \unicode{f4a1}\left\{\left(a^2 \unicode{f817}^3+a\right)
  \unicode{f818}(\unicode{f817})+\left(2 \unicode{f817}^3 a-1\right)
  \unicode{f818}'(\unicode{f817})+\unicode{f817}
  \unicode{f818}''(\unicode{f817})=0,
  \unicode{f818}(1)=c_1,\unicode{f818}'(1)=c_2\right\}\right)(x)\right\}\right\}$

\end{document}

I can show only the start, as the formula is unbreakable due to the wrong usage of \left and \right. Whoever wrote the LaTeX code generator doesn't seem to know much about TeX.

enter image description here

Here is the typeset result after removing all \left and \right:

enter image description here

egreg
  • 1,121,712
3

You can add the following code before automatic generated text:

\def\unicode#1{\csname U+#1\endcsname}
\def\unidef#1{\expandafter\def\csname U+#1\endcsname}

\unidef{f818}{{\bdot{\dot y}}}
\unidef{f817}{{\bdot{\dot x}}}
\unidef{f4a1}{,}

\def\bdot#1{\vtop{\offinterlineskip
   \halign{\hfil##\hfil\cr$#1\vphantom y$\cr\noalign{\vskip1pt}.\cr}}}

% the text generated by Mathematica follows:

\documentclass[12pt]{article} 
\usepackage{amsmath,mathtools}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[mathletters]{ucs}
\usepackage[utf8]{inputenc}
\begin{document}

$\left\{\left\{y(x)\to \text{DifferentialRoot}\left(\{\unicode{f818},
  \unicode{f817}\}
  \unicode{f4a1}\left\{\left(a^2 \unicode{f817}^3+a\right) 
  \unicode{f818}(\unicode{f817})+\left(2 \unicode{f817}^3 a-1\right) 
  \unicode{f818}'(\unicode{f817})+\unicode{f817} 
  \unicode{f818}''(\unicode{f817})=0,
  \unicode{f818}(1)=c_1,\unicode{f818}'(1)=c_2\right\}\right)(x)\right\}\right\

\end{document}

I mean that you need to print dot above and below of x, y, thus \bdot is defined.

wipet
  • 74,238
  • Those dots seem artifacts; I've never seen such a notation. – egreg Jul 22 '14 at 09:02
  • @egreg I never seen such notation too. But the question includes: "...which uses special Mathematical symbols (small dot above and below letters) as shown...". IMHO, the problem with \unicode macro in the autogenerated text originates from this. – wipet Jul 22 '14 at 09:12