7

Recently, I'm learning how to use Mathematica, and I want to make some notes with LaTeX. I noticed that Mathematica have provide a function "TeXForm", but when dealing with this:

enter image description here

the output is \text{Graph}[\{a\unicode{f3d5}b\}]

I know what the \unicode{} command is, because when I use "ExportString" in the Mathematica, I got

%% AMS-LaTeX Created with the Wolfram Language : www.wolfram.com
\documentclass{article}
\usepackage{amsmath, amssymb, graphics, setspace}
\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{{}}
\newcounter{mathematicapage}
\begin{document}
\[\text{Graph}[\{a\unicode{f3d5}b\}]\]
\end{document}

However, when I when I generated the pdf file, I got only

enter image description here

It is obvious that the symbol between a and b isn't displayed.

Then I looked up for the Unicode f3d5 in the font MathematicaMono (the font mathematica used to display symbols), I found the symbol I want, but how can I put this symbol (or character) into my pdf file, that is, how to apply this symbol to the latex environment displaymath.

By the way, I'm using WinEdt10.1, with MiKTeX and PDFTeXify (PDFLaTeX, LuaLaTeX, XeLaTeX or others are also available).

  • 1
    See this answer, which can be adapted to suit your issue. But, basically, you need to redefine \unicode so it prints something (right now it does not); and it would be useful to use either xelatex or lualatex to compile. – jon Feb 15 '17 at 3:46
  • there are files with more or less standard mappings between unicode numbers and tex command names, eg uniocde-math-table.tex in the unicode-math package, however despite the name of the command mathematica is not using unicode here, or at least only superficially. U+F353 is not a defined unicode code point, it is part of the "private use area" so you will need to define \unicode{f3d5} to make a suitable arrow. – David Carlisle Feb 15 '17 at 11:44
  • @jon Much appreciated, your answer gave me inspiration. Now I can correctly insert certain symbols using XeLaTeX with package fontspec and the command \symbol. There is a small problem: I'd like to make it a new command using \newcommand{\unicode}{\textnormal{\fontspec{MathematicaMono}\symbol{"#1}}} or \newcommand{\unicode}{\textnormal{\fontspec{MathematicaMono}^^^^#1}}, but neither of them works. The first one can not recognize the lower case like f3d5. And the second one tries to convert ^^^^#1 to a Unicode char, causing compile error. If there is a solution can solve them? – Rui LIU Feb 15 '17 at 16:03
  • @DavidCarlisle Also thanks. Indeed, the Unicode f3d5 is in the "Private use area", however, I can find it out from the Mathematica font file --- MathematicaMono.ttf. Currently, the problem I'm facing becomes how should I (re)define \unicode to insert these symbols easily ,(two atempts are shown above), because the Mathematica can only generate code points in lowercases, that is, it can only generate f3d5, but not F3D5, which can be used by \symbol directly, and I can't find such a command to convert an parameter into its uppercase. – Rui LIU Feb 15 '17 at 16:30
  • Instead of \symbol{"#1} try \uppercase{\symbol{"#1}}. – Bruno Le Floch Feb 16 '17 at 16:59
2

Thanks for all of you, @jon, @DavidCarlisle and @BrunoLeFloch. Without your help, I can't solve this problem on my own.

Here is a sample showing how should I do to solve it. With winedt10.1, XeLaTeX, and package fontspec.

\documentclass{article}
\usepackage{fontspec} %this line is added.
\usepackage{amsmath, amssymb, graphics, setspace}
\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{\textnormal{\fontspec{MathematicaMono}\uppercase{\symbol{"#1}}}} %this line is modified.
\newcounter{mathematicapage}
\begin{document}
\[\text{Graph}[\{a\unicode{f3d5}b\}]\]
\end{document} 

Except the line with comment, the other lines are directly generated by Mathematica.

And that is the key:

\newcommand{\unicode}[1]{\textnormal{\fontspec{MathematicaMono}\uppercase{\symbol{"#1}}}}

Of course, you need to install the font MathematicaMono first, then you can import your formula directly from the Mathematica without any modification.


A better version of the code:

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{fontspec}

\newfontfamily{\mathematicamono}{MathematicaMono}

\ExplSyntaxOn
\NewDocumentCommand{\mmono}{m}
 {
  \text{\mathematicamono#1}
 }
\NewDocumentCommand{\unicode}{m}
 {
  \mmono { \symbol { \int_from_hex:n { #1 } } }
 }
\ExplSyntaxOff

\begin{document}

\[\text{Graph}[\{a\unicode{f3d5}b\}]\]

\[\text{Graph}[\{a\mathrel{\unicode{f3d5}}b\}]\]

\end{document}

enter image description here

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.