3

I know there are several approaches to highlight a piece of code with TeX. I tried the following

\documentclass[a4paper,11pt,naustrian]{article}
\usepackage[left=2.5cm, right=2.5cm, top=4.3cm, bottom=2cm, headheight=2.3cm]{geometry} % for margins on a A4paper
\usepackage{fontspec}
\usepackage[shorthands=off,bidi=basic]{babel}
\setmainfont{Open Sans}
\usepackage{parskip} 
\usepackage[font=small]{caption} % small font, an additional line as space after figure

\usepackage[dvipsnames, table]{xcolor}
\usepackage{luacolor,lua-ul} %for usage of style attributes - background color

\begin{document}
\newcommand{\code}[1]{ \highLight[{[HTML]{D3D3D3}}]{\texttt{#1}}}
* Die Kapiteln können nur dann in der Lasche \code{Bearbeiten} gesehen werden, wenn der Benutzer im Gesamtdokument die Berechtigung \code{Zugang} hat.
\end{document}

Which produces the following result:

enter image description here

The major problem with this result is that the colored background doesn't start at the word boundary. In first word it includes a space which in the second not. I can remove the space in the command code but than the background color starts directly with the preceding word.

Is this a problem from lua-ul? Or how to define it more precisely to wrap the word boundaries?

Running lualatex 1.13.2. The above screenshot was made with lua-ul 0.1.2 but is in a different form still not correct in 0.1.3. Therefore I thought it might be a more general issue.

3 Answers 3

4

The issue is the combination of \highLight and \texttt, which seems like a bug. You could try reporting it on https://github.com/zauguin/luaul/issues.

A workaround is to reverse the order and put the highlight inside the teletype (without any spaces):

\newcommand{\code}[1]{\texttt{\highLight[{[HTML]{D3D3D3}}]{#1}}}

Result:

enter image description here

1
  • Thx for the approach. I didn't think about the reverse order :-)
    – LeO
    May 12, 2021 at 12:11
3

text commands like \texttt don't simply switch the font. They also at the begin check the "italic correction". If you compare this

{\itshape abt \textup{k}}

{\itshape abt \upshape k}

you can see a slight difference:

enter image description here

The code does an \unskip and then reinserts the space, and that is what you are seeing.

To avoid this side-effect either move the \texttt to the outside, or use internally \ttfamily.

2

This is fixed in lua-ul version v0.1.4:

\documentclass[a4paper,11pt,naustrian]{article}
\usepackage[left=2.5cm, right=2.5cm, top=4.3cm, bottom=2cm, headheight=2.3cm]{geometry} % for margins on a A4paper
\usepackage{fontspec}
\usepackage[shorthands=off,bidi=basic]{babel}
\setmainfont{Open Sans}
\usepackage{parskip} 
\usepackage[font=small]{caption} % small font, an additional line as space after figure

\usepackage[dvipsnames, table]{xcolor}
\usepackage{luacolor,lua-ul} %for usage of style attributes - background color

\begin{document}
\showoutput
\newcommand{\code}[1]{ \highLight[{[HTML]{D3D3D3}}]{\texttt{#1}}}
* Die Kapiteln können nur dann in der Lasche \code{Bearbeiten} gesehen werden, wenn der Benutzer im Gesamtdokument die Berechtigung \code{Zugang} hat.
\end{document}

enter image description here

You must log in to answer this question.

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