3

I have modified the \texttt{} command based on this answer to give the rendered text a highlight:

\let\OldTexttt\texttt
\renewcommand{\texttt}[1]{\OldTexttt{\hl{#1}}}

I am not experienced in TeX, so I don't really know what the command does and what side effects it has. All I know is that it has added the highlight. There are obviously some problems because a rendered text with a dash in it is missing its last character.

Source code (minimal working example /as requested/):

\documentclass[12pt,oneside,final]{fithesis2}

\usepackage[czech]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{soul}
\usepackage{xcolor}

\definecolor{gray}{rgb}{0.95,0.95,0.95}

\sethlcolor{gray}

\let\OldTexttt\texttt
\renewcommand{\texttt}[1]{\OldTexttt{\hl{#1}}}

\begin{document}

\texttt{game-server.js}

\end{document}

If needed, fithesis2 is downloadable from the website of our university by clicking on Soubory třídy fithesis2 jako ZIP, cca 880 KiB.

Compiled PDF:

Compiled PDF

I have tried to remove the \texttt{} modification and it fixed the problem with the missing character, but I would actually like to keep the highlight. Removing \usepackage[czech]{babel} also helps but I guess I need that line because I'm writing in Czech. (?)

Removing the \texttt{} modification also breaks line-breaking which now doesn't happen inside the text rendered by \texttt{} at all, so now I'm left with some lines going over the right edge.

How to do it so that I can have all of it - the highlight, working line-breaking and dashes possible?

Thank you.

zbr
  • 133
  • Could you show us the preamble you're using? Even better, could you show a minimal working example (MWE)? – Ignasi May 10 '16 at 14:39
  • 2
    You obviously redefined \texttt (or it wouldn't have such a gray background). So only you can know why it behaves so curiously. – Ulrike Fischer May 10 '16 at 14:48
  • @UlrikeFischer: You're right. I have modified the question accordingly. Thank you for reading it again. – zbr May 10 '16 at 15:15
  • @Zabri Please, add an example of the code you're using. – egreg May 10 '16 at 15:18
  • @egreg: Done... – zbr May 10 '16 at 16:00
  • You would make it so much easier to help you if you'd (1) take your code (2) boil it down to a few lines of code that still show that behavior (minimal working example) (3) and post those lines here (not as a picture, but as text). This way people could try and help you solve the issue. With what you are giving them here, they can only guess – sheß May 10 '16 at 16:30
  • 1
    I have modified the question and added a MWE. – zbr May 10 '16 at 16:44
  • Now it's much clearer: it seems an incompatibility of soul with babel-czech. – egreg May 10 '16 at 17:16

1 Answers1

3

It is an incompatibility between soul and babel-czech (and babel-slovak as well). When doing its working, soul looks for a standard - and it doesn't find it even if it appears to be there, because babel-czech changes the hyphen into an active character.

Thus the problem appears only when a hyphen is found in the argument to \hl, because the character count is off by one.

Here's a workaround.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[czech]{babel}

\usepackage{soulutf8}
\usepackage{xcolor}
\usepackage{regexpatch}

\makeatletter
\regexpatchcmd*{\SOUL@eval}{\cO\-}{\cA\-}{}{}
\makeatother

\definecolor{gray}{rgb}{0.95,0.95,0.95}

\sethlcolor{gray}

\begin{document}

\hl{abc-def}

\hl{abcdef}

\end{document}

enter image description here

Here's it for your minimal example; note the small changes I made, notably the usage of utf8 instead of utf8x, soulutf8 instead of soul and a better redefinition of \texttt.

\documentclass[12pt,oneside,final]{fithesis2}

\usepackage[czech]{babel}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{soulutf8}
\usepackage{letltxmacro}
\usepackage{regexpatch}

\makeatletter
\regexpatchcmd*{\SOUL@eval}{\cO\-}{\cA\-}{}{}
\makeatother

\definecolor{gray}{rgb}{0.95,0.95,0.95}

\sethlcolor{gray}

\LetLtxMacro\OldTexttt\texttt
\DeclareRobustCommand{\texttt}[1]{\OldTexttt{\hl{#1}}}

\begin{document}

\hl{game-server.js}

\texttt{game-server.js}

\end{document}

enter image description here

egreg
  • 1,121,712