1

This question already has an answer here:

I'd like to have shorter underscores with LuaTex and fontspec. And the vertical position of the underscores is too low compared to not using fontspec.

Do I have to use some other setup than fontspec. It is working quiet well except for the too long underscores.

Result without fontspec

result without fontspec

1. MWE

\documentclass[]{article}
\usepackage[]{fontspec}

\begin{document}
cöde\_nameß

\texttt{cöde\_nameß}

\textit{cöde\_nameß}

\end{document}

enter image description here


I tried https://tex.stackexchange.com/a/128817 but there is a still a difference between texttt and the others.

2. MWE

\documentclass[]{article}
\usepackage[]{fontspec}
\usepackage{relsize}
\begin{document}
\renewcommand{\_}{\textscale{.7}{\textunderscore}}

cöde\_nameß

\texttt{cöde\_nameß}

\textit{cöde\_nameß}

\end{document}

enter image description here


I also tried https://tex.stackexchange.com/a/81980/61217 but then the font of the underscore doesn't match the texttt.

3. MWE

\documentclass[]{article}
\usepackage[]{fontspec}
\makeatletter
\let\_\relax
\DeclareRobustCommand{\_}{%
  \leavevmode\vbox{%
    \hrule\@width.5em
          \@height-.26ex
          \@depth\dimexpr.26ex+.28pt\relax}}
\makeatother
\begin{document}

cöde\_nameß

\texttt{cöde\_nameß}

\textit{cöde\_nameß}

\end{document}

enter image description here

marked as duplicate by Alan Munn, egreg fontspec Aug 5 '17 at 20:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Be aware that if you redefine \textunderscore as a rule that it won't copy & paste correctly. – Ulrike Fischer Aug 5 '17 at 20:50
  • @AlanMunn see my thrid MWE. It is not working for me. Also the vertical position of the underscore differ form the example without fontspec. – goofyno Aug 5 '17 at 20:52
  • 2
    Ultimately this is a font issue, it's not really a case of something "not working". The Latin Modern underscores are the way they are, and there are various ways around that, the best of which would be to find a font whose underscores you like. – Alan Munn Aug 5 '17 at 20:55
  • 1
    I added another possibility to the old question: tex.stackexchange.com/a/384997/2388 – Ulrike Fischer Aug 5 '17 at 22:14