$\{A\leqslant x\leqslant B\}$

Copy the code into Notebook, and you'll lose the less sign, this can be rendered well in Mathematica.StackExchange

$\{A\leqslant x\leqslant B\}$

And you can also ImportString["$\{A\\leqslant x\\leqslant B\\}$","TeX"]//CreateDocument,

Here is the problem, the leqslant was removed, are there any options of ImportString or are there any other methods to Import some latex codes without losing some information?

  • $\begingroup$ It seems you need something like the "ConversionRules" option but in the opposite direction, as that appears to be only for conversion into LaTex. $\endgroup$ – Mr.Wizard Sep 3 '13 at 10:38

No, there are no (documented) options of ImportString directly.

But who cares? Just get rid of leqslant, e.g., like this:

ImportString["$\{A\\leqslant x\\leqslant B\\}$" /.
  s_ String :> StringReplace[s,"leqslant" -> "leq"], "TeX"] // CreateDocument
| improve this answer | |
  • $\begingroup$ yes, this is one way, the bad thing, I should build one replace rules, I'll use it if no better methods. $\endgroup$ – HyperGroups Sep 3 '13 at 10:26

This is longer than a comment, but does not provide a solution (obviously, Rolf's answer does the job perfectly).

Spelunking in ImportString reveals that it uses the same options as Import. Import on the other hand uses a set of private functions, one for each import format, with different option-sets. We are interested in $TeX$ import options. Ultimately, in the definition of System`Convert`TeXImportDump`validateInput, the following options are listed:

"InstallDir" :> System`Convert`TeXImportDump`$TeX2NBDir,
"OutputFile" -> None,
"InputPath" -> {},
"TeXCommand" -> "\\input amsmath.tns %\n",
"Verbose" -> False,
"StyleDefinitions" -> Null,
"MathLink" -> True,
"FEKernel" -> True,
"MathCommand" -> "math",
"MathLinkDebug" -> False,
"NotebookDebug" -> False,
"FullDebug" -> False,
"LogFile" -> Null,
"BaseFormat" -> Null,
"Flush" -> False,
"CoreDump" -> False,
"Raw" -> False,
"Normalize" -> True

General options are:

Path :> $Path,
ConversionOptions,(* Obsolete after v6.0 *)
CharacterEncoding -> "UTF8"

Using ImportString[..., "Verbose" -> True] reveals that we are indeed using the amsmath.tns file, that is the Wolfram interface for amsmath.sty. It's quite easy to figure out that \leqslant is defined in the amssymb.sty and amssymb.tns files (the .tns files can be found at FileNameJoin@{$InstallationDirectory, "\\SystemFiles\\IncludeFiles\\TeX\\Import"}, the same location the "InstallDir" option uses as a default). I'm not a $TeX$ expert, so I've tried simply to include more packages with \include in the "TeXCommand" option, perhaps this is not the way to go (though "Verbose" -> True indicates that both packages are parsed):

   ImportString["$\\{A\\leqslant x\\leqslant B\\}$", "TeX", (* "Verbose" -> True, *)
    "TeXCommand" -> "\\input amsmath.tns \\input amssymb.tns %\n"]

enter image description here

indicating that the symbols are there, but are displayed incorrectly. I've tried different encodings (found under FileNameJoin@{$InstallationDirectory, "\\SystemFiles\\CharacterEncodings"}), with no avail. According to amssymb.tns, the unicode character code for \leqslant is unicode 2270 (it also means that Mathematica in theory does support \leqslant).

One might want to play with CharacterEncoding, or with the "InstallDir" option (by pointing to a non-WRI $TeX$ installation) or with the "StyleDefinitions" option. If you have more experience with $TeX$ than me, please feel free to improve this post!

| improve this answer | |

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.