3

I am trying to use lualatex with the unicode-math and semantic packages. I have some problems with the semantic package - when I load full version or with the shorthand option I get "Invalid math code" errors.

The following code works correctly:

\documentclass{scrreprt}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{TeX Gyre Termes}

\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{Asana Math}

\usepackage[inference]{semantic}

\begin{document}
$$
\inference{a = b}{c}{d}
$$
\end{document}

And this one causes errors:

\documentclass{scrreprt}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{TeX Gyre Termes}

\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{Asana Math}

\usepackage[inference,shorthand]{semantic}

\begin{document}
$$
\inference{a = b}{c}{d}
$$
\end{document}

Is there any way to make it work? Or maybe there is a way to create semantic bracket symbols to use with unicode-math? (like \ldbrack \rdbrack in mathabx package).

1
  • 2
    Welcome to TeX.SE! You can use backticks, like this "`", to highlight TeX syntax items in your text. I've added some of them.
    – Mico
    Commented Jan 31, 2012 at 8:46

2 Answers 2

3

The following hack seems to solve the problem: load the semantic package but embedding the call in some magic code

\let\ORImathcode\mathcode
\let\mathcode\Umathcodenum

\usepackage[inference,shorthand]{semantic}

\let\mathcode\ORImathcode

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\mathligsoff}{\mathcode}{\Umathcodenum}{}{}
\xpatchcmd{\@addligto}{\mathcode}{\Umathcodenum}{}{}
\xpatchcmd{\@addligto}{\mathcode}{\Umathcodenum}{}{}
\xpatchcmd{\@addligto}{\mathcode}{\Umathcodenum}{}{}
\makeatother

In short we tell ligature.sty (that is loaded by semantic) to use \Umathcodenum where it uses \mathcode.

If xpatch is not available, the lines from \usepackage{xpatch} can be changed into

\usepackage{etoolbox}
\makeatletter
\expandafter\patchcmd\csname mathligsoff \endcsname{\mathcode}{\Umathcodenum}{}{}
\patchcmd{\@addligto}{\mathcode}{\Umathcodenum}{}{}
\patchcmd{\@addligto}{\mathcode}{\Umathcodenum}{}{}
\patchcmd{\@addligto}{\mathcode}{\Umathcodenum}{}{}
\makeatother

EDIT

A version that can work with all three engines

\usepackage{ifxetex,ifluatex}
\newif\ifunicodeengine
\ifxetex
  \unicodeenginetrue
  \let\SEMmathcodenum\XeTeXmathcodenum
\else
  \ifluatex
    \unicodeenginetrue
    \let\SEMmathcodenum\Umathcodenum
  \fi
\fi
\ifunicodeengine
  \let\ORImathcode\mathcode
  \let\mathcode\SEMmathcodenum
\fi

\usepackage[inference,shorthand]{semantic}

\ifunicodeengine
  \let\mathcode\ORImathcode

  \usepackage{xpatch}
  \makeatletter
  \xpatchcmd{\mathligsoff}{\mathcode}{\SEMmathcodenum}{}{}
  \xpatchcmd{\@addligto}{\mathcode}{\SEMmathcodenum}{}{}
  \xpatchcmd{\@addligto}{\mathcode}{\SEMmathcodenum}{}{}
  \xpatchcmd{\@addligto}{\mathcode}{\SEMmathcodenum}{}{}
  \makeatother
\fi
0
0

Thanks, I managed to bypass this in a little different fashion. I wanted to use \eval so I don't use shorthand, just redefine interesting part (turns out there is an \rBrack symbol ):

\usepackage[inference]{semantic}
\newcommand{\evalsymbol}[1][]{\ensuremath{\mathcal{E}^{#1}}}
\newcommand{\eval}[3][]%
  {\mbox{${\evalsymbol}^{#1}\lBrack${#2}$\rBrack$}\,{#3}}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .