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
1. MWE
\documentclass[]{article}
\usepackage[]{fontspec}
\begin{document}
cöde\_nameß
\texttt{cöde\_nameß}
\textit{cöde\_nameß}
\end{document}
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}
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}




fontspec. – goofyno Aug 05 '17 at 20:52