Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
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 Jan 31 '12 at 8:46
add comment

2 Answers

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
share|improve this answer
add comment

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}}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.