2

I am working on a programming language semantics text, and decided to use the semantic package. According to the manual, I can use this:

\reservestyle[\mathrel]{\command}{\mathbf}
\command[\mathrel]{skip,while,do,if,then,else}

to use, among reserved words, the same spacing that LaTeX uses for relational operators. However, it doesn't seem to work:

\documentclass{article}
\usepackage{semantic}
\usepackage{braket}

\reservestyle[\mathrel]{\command}{\mathbf}
\command[\mathrel]{skip,while,do,if,then,else}

\begin{document}

\[
\inference[ifTrue]
            {\braket{S_1,s} -> s'}
            {\braket{\<if> b \<then> S_1 \<else> S_2,s} -> s'}
\]

\end{document}

The result is this:

enter image description here

It seems like \mathrel isn't working. Did I do anything wrong? Or, is there a way to get reasonable spaces around reserved words, without having to type \; several times?

I am using pdflatex; the version is:

$ pdflatex --version
pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian)
kpathsea version 6.2.1
...
Compiled with libpng 1.6.17; using libpng 1.6.17
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with poppler version 0.38.0
  • 1
    Interesting question. I don't see what's wrong, you strictly follow the manual's guidance… – Clément Jan 8 '16 at 16:54
2

I think it's the other way around:

\documentclass{article}
\usepackage{semantic}
\usepackage{braket}

\reservestyle{\command}{\mathrel}
\command[\mathbf]{skip,while,do,if,then,else}

\begin{document}

\[
\inference[ifTrue]
            {\braket{S_1,s} -> s'}
            {\braket{\<if> b \<then> S_1 \<else> S_2,s} -> s'}
\]

\end{document}

enter image description here

Just to go further into the details, if I do

\reservestyle[\mathrel]{\test}{\mathbf}
\test{foo}
\test[\mathrel]{baz}

\expandafter\show\csname<foo>\endcsname
\expandafter\show\csname<baz>\endcsname

as suggested by the package, I get

> \<foo>=macro:
->\mathbf {\mathrel {foo}}.

> \<baz>=macro:
->\mathbf {\mathrel {baz}}.

and it's clear what goes wrong about spacing.

It's an apparent bug in the definition of \@xdefineReserved, where the commands \@@formating and \@@spacing are swapped.

\documentclass{article}
\usepackage{semantic}

\makeatletter
\def\@xdefineReserved#1[#2]#3\END{%
  \def\reserved@a{#2}%
  \ifx \reserved@a\empty \toks0{#1}\else \toks0{#2} \fi
    \expandafter\edef\csname\expandafter<#1>\endcsname
    {\the\@@spacing{\the\@@formating{\the\toks0}}}}
\makeatother

\reservestyle[\mathrel]{\command}{\mathbf}
\command{skip,while,do,if,then,else}

\begin{document}

$\<if> b \<then> S_1 \<else> S_2,s -> s'$

\end{document}

enter image description here

So the documentation is right, but the implementation went wrong.

  • 1
    Thank you! Works perfectly. The manual should probably be fixed, though... – Jay Jan 8 '16 at 17:54
  • 1
    Its last update dates back to 2003… However, the addresses of the authors in the documentation still seems to be correct, you can drop them a line. – Clément Jan 8 '16 at 18:12
  • 1
    @Clément Yes, it's indeed a bug in the package, where two commands got their places traded. – egreg Jan 8 '16 at 18:54
  • @Clément Mail sent – egreg Jan 8 '16 at 22:57

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.