3
\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1,T2A]{fontenc}

\usepackage{listings}
\usepackage{dejavu}
\usepackage{upquote}

\lstset{
    basicstyle=\ttfamily\footnotesize
}

\begin{document}
\lstinline|4 `div` 2|
\end{document}

shows 4 div 2 without the backticks. No errors or warnings in the log. Adding textcomp and using upquote in lstset instead of the separate package didn't help.

Can anyone reproduce it (since search doesn't find anything and it would be weird if I was the first who needed this character)?

And is there a workaround?

  • Some months before I discovered that not many fonts contains the backticks even using XeLaTeX... I will test it with XeLaTeX to see if is a matter of font... (I think it is) – koleygr Feb 18 '18 at 12:27
  • Tested and works fine with XeLaTeX and DejaVu Sans Mono... So, please wait for someone else's answer – koleygr Feb 18 '18 at 13:10
  • The TS1 fonttable of dejavu Sans is missing quite a lot of glyphs, beside other \textasciigrave used by upquote. There is a grave in the font so one could add it, but this means that someone would have to recreate the tfm/enc etc. You could try literate={`}{\`{}}2 instead. – Ulrike Fischer Feb 18 '18 at 15:01
2

If you look in the log file, you'll see

Missing character: There is no ` in font DejaVuSansMono-tlf-ts1!

The upquote package defines ` to produce \textasciigrave, which is taken from the TS1 encoded font. Unfortunately, this glyph is missing in DejaVu Mono in the TS1 encoding. We can borrow it from Vera Sans that has it (thanks to the OP for suggesting it over cmtt).

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1,T2A]{fontenc}

\usepackage{listings}
\usepackage{dejavu}
\usepackage{upquote}
\usepackage{etoolbox}

\makeatletter
\chardef\straightquote@code=\catcode`'
\chardef\backquote@code=\catcode``
\catcode`'=\active \catcode``=\active
\patchcmd{\@noligs}
 {\textasciigrave}
 {\fixedtextasciigrave}
 {}{}
\newcommand{\fixedtextasciigrave}{%
  \makebox[.5em]{\fontencoding{TS1}\fontfamily{fvs}\selectfont\textasciigrave}% Vera Sans
}
\catcode\lq\'=\straightquote@code
\catcode\lq\`=\backquote@code
\makeatletter

\lstset{
  columns=fullflexible,
  keepspaces,
  basicstyle=\ttfamily\footnotesize,
  literate={`}{{{\fixedtextasciigrave}}}1,
}

\begin{document}

\lstinline|4 `div` 2|

\begin{lstlisting}
4 `div` 2
\end{lstlisting}

\end{document}

enter image description here

  • Thank you! Since DejaVu is based on Bitstream Vera, I modified the newcommand to just {\fontfamily{fvs}\selectfont\textasciigrave}%. 1001fonts.com/search.html?search=sans+mono&text=%60 shows that DejaVu one should be slightly wider, but it's still much closer. – Alexey Romanov Feb 18 '18 at 16:14
  • @AlexeyRomanov Good idea! I'll incorporate it (with a small change). – egreg Feb 18 '18 at 16:26
  • There is an extra closing brace in the command (can't make an edit because it's too small). – Alexey Romanov Feb 18 '18 at 16:38
  • @AlexeyRomanov FIxed – egreg Feb 18 '18 at 16:40

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.