如何使用 Alex Chan 实现的“非常好的下划线”功能对宏中的文本进行下划线

如何使用 Alex Chan 实现的“非常好的下划线”功能对宏中的文本进行下划线

按照 David Carlisle 的回答如何为宏中的文本(包括换行符)添加下划线?,我试图将 David Carlisle 使用 \expandafter 来允许换行(当使用 soul 包中的 \uline 为文本添加下划线时)改编为 Alex Chan 在其网页上实现的“非常漂亮的下划线”在 LATEX 中为文本添加下划线的四种方法

\documentclass{scrreport}
\usepackage[showframe]{geometry}
\usepackage{soul, ulem}

% From Alex Chan's web page 'Four ways to underline text in LATEX' *
\usepackage{contour}
\renewcommand{\ULdepth}{1.8pt}
\contourlength{0.8pt}

% From Alex Chan's web page 'Four ways to underline text in LATEX' *
\newcommand{\myuline}[1]{%
  \uline{\phantom{#1}}%
  \llap{\contour{white}{#1}}%
}

% My 1st permutation of David Carlisle's code: \mXuline
\newcommand{\mXuline}[1]{%
  \expandafter\uline{\phantom{#1}}%
  \llap{\contour{white}\expandafter{#1}}%
}

% My 2nd permutation of David Carlisle's code: \mZuline
\newcommand{\mZuline}[1]{%
  \expandafter\uline{\expandafter\phantom{#1}}%
  \expandafter\llap{\contour{white}\expandafter{#1}}%
}

%%% In class definition:
% Default value
\def\printtitle{default title}
% Provide command for user to set own title
\newcommand{\settitle}[1]{\def\printtitle{1) #1}}%

%%% In preamble to the document --> visible to the user
%\settitle{my own title}
\settitle{long title for testing long title for testing long title for testing long title for testing long title for testing }

\begin{document}
    
    \vspace{5mm}
    David Carlisle's answer incorporates \verb|\expandafter| to allow for line-breaks when underlining with macro expansion using the \verb|\uline| command from the soul package.  

% \uline with \expandafter
    \expandafter\uline\expandafter{\printtitle}

    \vspace{5mm}

    Using Alex Chan's code, I would like my underlines ( using \verb|\uline{}| ) to be drawn "on a consistent level, flush against the bottom of the text, with gaps as appropriate for descenders" as shown immediately below, but also breaking at the end of the line which it currently does not do. 

    \vspace{5mm}
    
% \uline using \myuline from Alex Chan's web page 'Four ways to underline text in LATEX' *
    \myuline{2) long title for testing long title for testing long title for testing long title for testing long title for testing} 

    \vspace{5mm}
    My 1st permutation of David Carlisle's answer incorporating  \verb|\expandafter| to allow for line-breaks when underlining using Alex Chan's code; it fails to break at the end of the line.

% \uline using \mXuline - 1st attempt to implement \expandafter akin to David Carlisle's solution 
    \mXuline{3) long title for testing long title for testing long title for testing long title for testing long title for testing} 

    \vspace{5mm}
    My 2nd permutation of David Carlisle's answer incorporating  \verb|\expandafter| to allow for line-breaks when underlining using Alex Chan's code; it also fails to break at the end of the line.

% \uline using \mZuline - 2nd attempt to implement \expandafter akin to David Carlisle's solution 
    \mZuline{4) long title for testing long title for testing long title for testing long title for testing long title for testing} 

\end{document}

% https://alexwlchan.net/2017/latex-underlines/

我尝试对 David Carlisle 的 \expandafter 代码进行一些改动,以实现 Alex Chan 的“非常漂亮的下划线”实现,但是无济于事。

任何可以补充我有限的 LaTeX 技能的想法都将受到赞赏。

注:我是不是使用 LuaLaTeX,因此 Marcel Krüger 发布的答案对我来说不可用。

相关内容