So I was looking at underline omitting the descenders and wanted a version where I could control the underline thickness. Using the basic idea from the answers there, I came up with a method that has a couple of issues that I don't understand.
- If I underline a single word the spacing seems to be fine, however if I underline a longer sentence it seems that the text is getting shifted to the right (ie. the underline ends before the sentence does)
- Things become a mess if I change the font (uncomment
\usepackage{tgheros}) - Things become an even larger mess if I use
\usepackage[T1]{fontenc}when I get pixelated text.
Can anyone point out where I've gone wrong? I would include the output but I'm not sure how to enlarge it enough to show the problem clearly without it looking terrible.
\documentclass{article}
%\usepackage{tgheros}
%\usepackage[T1]{fontenc}
\renewcommand*\familydefault{\sfdefault}
\usepackage{xcolor}
\usepackage{xparse}
\ExplSyntaxOn
\box_new:N \text_box
\fp_new:N \l_tmpa_fp
%1st optional is width of gap, 2nd is thickness of rule, 3rd is vertical height of rule
\NewDocumentCommand \gapul {O{10} D<>{.05} D(){.2} m}
{
\tl_gset:Nn \g_tmpa_tl {#4}
\hbox_set:Nn \text_box {#4}
{
\ooalign{
\rule[-#3ex]{\box_wd:N \text_box}{#2ex}\cr
\prg_stepwise_function:nnnN {1}{1}{#1}\write_white_text:n
\box_use:N \text_box\cr}
}
}
\cs_new:Npn \write_white_text:n #1
{
\fp_set:Nn \l_tmpa_fp {.05}
\fp_mul:Nn \l_tmpa_fp {#1}
\hspace{\fp_to_dim:N \l_tmpa_fp}\textcolor{white}{\g_tmpa_tl}\cr
\hspace{-\fp_to_dim:N \l_tmpa_fp}\textcolor{white}{\g_tmpa_tl}\cr
}
\ExplSyntaxOff
\begin{document}
\gapul{japan}
\gapul{japan giddy quid japan}
\end{document}
Edit: Can anyone explain what is happening when write_white_text is changed to the following:
\cs_new:Npn \write_white_text:n #1
{
\fp_set:Nn \l_tmpa_fp {.05}
\fp_mul:Nn \l_tmpa_fp {#1}
\hspace{\fp_to_dim:N \l_tmpa_fp}\textcolor{red}{\g_tmpa_tl}\cr
%\hspace{-\fp_to_dim:N \l_tmpa_fp}\textcolor{white}{\g_tmpa_tl}\cr
}
Although the \hspace is positive (??) the words at the start are getting shifted in both a positive and negative direction and the shift in the negative direction diminishes across words. Boxing the text causes the shift to be consistent across words.
