CamelCaseClassNames 的连字:混合自动和手动?

CamelCaseClassNames 的连字:混合自动和手动?

我的文本包含一些较长的 CamelCaseClassNames,而 LaTeX 不喜欢自动将其连字符化。我\camelhyph项目:latexcamel并且它可以完美地实现每个大写字母前的自动连字。

但是,我还想允许在类名中的一些较长的单词中使用连字符。只要我\camelhyph对包含该宏的任何内容使用该宏,\\-它就会失效。

有人能解决这个问题吗?

\documentclass{article}

\usepackage{xspace}
\usepackage{ifthen}

\makeatletter
  \newcommand{\camelhyph}[1]{\@fterfirst\c@amelhyph#1\relax }
  \def\@fterfirst #1#2{#2#1}
  \def\c@amelhyph #1{%
   \ifthenelse{\equal{#1}\relax}{}{%  Do nothing if the end has been reached
     \ifnum`#1<91 \-#1\else#1\fi%     Check whether #1 is an uppercase letter,
                                %     if so, print \-#1, otherwise #1
    \expandafter\c@amelhyph%    %     insert \c@amelhyph again.
}}
\makeatother


\newcommand{\cclass}[1]{\texttt{\camelhyph{#1}}\xspace}
\begin{document}


Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Curabitur vitae lectus augue. Duis vitae quam sem. 
Integer rhoncus tempor est et convallis. Ddonec orciodio, 
facilisis in portaeget,  
\cclass{MySpecialCamelCaseLooooooongwooooordClassName} 
ornare veltortor. Pellentesque sed risus sed dolor iaculis
malesuada vitae ac purus. Praesent convallis mattis faucibus.
Nulla gravida ante id sapien tincidunt nec suscipit magna placerat. 

%not working because of the additional breakmark: \-
%Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
%Curabitur vitae lectus augue. Duis vitae quam sem. 
%Integer rhoncus tempor est et convallis. Ddonec orciodio, 
%facilisis in portaeget,  
%\cclass{MySpecialCamelCaseLooooooongwooo\-oordClassName} 
%ornare veltortor. Pellentesque sed risus sed dolor iaculis
%malesuada vitae ac purus. Praesent convallis mattis faucibus.
%Nulla gravida ante id sapien tincidunt nec suscipit magna placerat. 

\end{document}

答案1

您还必须测试\-

\def\camelhyph#1{\c@melhyph#1\relax}
\def\c@melhyph#1{%
  \ifx#1\relax\else
    \ifx#1\-#1\else
      \ifnum`#1<91 \-\fi
      #1%
      \expandafter\expandafter\expandafter\c@melhyph\expandafter
    \fi
  \fi}

如果#1是,\relax我们就到末尾了;如果是,就\-插入它并继续;如果是大写字母,就插入\-,否则什么也不做;插入#1并继续。

答案2

\-命令括在括号中:{\-}

\documentclass{article}

\usepackage{xspace}
\usepackage{ifthen}

\makeatletter
  \newcommand{\camelhyph}[1]{\@fterfirst\c@amelhyph#1\relax }
  \def\@fterfirst #1#2{#2#1}
  \def\c@amelhyph #1{%
   \ifthenelse{\equal{#1}\relax}{}{%  Do nothing if the end has been reached
     \ifnum`#1<91 \-#1\else#1\fi%     Check whether #1 is an uppercase letter,
                                %     if so, print \-#1, otherwise #1
    \expandafter\c@amelhyph%    %     insert \c@amelhyph again.
}}
\makeatother


\newcommand{\cclass}[1]{\texttt{\camelhyph{#1}}\xspace}
\begin{document}


Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Curabitur vitae lectus augue. Duis vitae quam sem. 
Integer rhoncus tempor est et convallis. Ddonec orciodio, 
facilisis in portaeget,  
\cclass{MySpecialCamelCaseLooooooongwooo{\-}oordClassName} 
ornare veltortor. Pellentesque sed risus sed dolor iaculis
malesuada vitae ac purus. Praesent convallis mattis faucibus.
Nulla gravida ante id sapien tincidunt nec suscipit magna placerat. 

\end{document}

结果:

结果

相关内容