# LuaLaTeX + unicode-math + semantic package

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).

-
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 Jan 31 '12 at 8:46

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}{}{}
\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}{}{}
\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}{}{}

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}
{\mbox{${\evalsymbol}^{#1}\lBrack${#2}$\rBrack$}\,{#3}}
`