获取忽略括号内内容的命令?

获取忽略括号内内容的命令?

更新:@wipet 的回答几乎完美,唯一的问题似乎是它不能正确地与 配合使用safeinputenc:重音字符不能正确大写,奇怪的命令(例如){\'\i}会引发各种错误。例如,这不会发生在biblatex自己的上\MakeSentenceCase,所以我会把它留在这里,以防有人有任何想法。

另一个更新:\endcsname如果我在使用@wipet 命令的字段中使用 {\LaTeX},smartuppercase我会收到“缺少插入”错误。


我正在使用 biblatex 并且我这样做了:

\DeclareFieldFormat{uppercase}{\MakeUppercase{#1}}

所以当我想以大写形式打印字段时,我可以使用\printfield[uppercase]{title}

问题是这总是让一切大写,并且我想忽略括号中的内容,这样,例如,{an Introduction to {LaTeX}}打印为“LaTeX 简介”。我该怎么做?


平均能量损失

\begin{filecontents}{\jobname.bib}
@book{blabla,
 title = {São {Paulo}}}
\end{filecontents}

\documentclass{article}

\usepackage[safeinputenc, backend=biber, bibstyle=standard]{biblatex}
\addbibresource{\jobname.bib}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}

\def\traceparam#1{\def\paramL{}\traceparamA #1\end}
\def\traceparamA{\futurelet\next\traceparamB}
\def\traceparamB{%
   \let\nexts=\undefined
   \expandafter\ifx\space\next \let\nexts=\traceparamS \fi
   \ifx\bgroup\next \let\nexts=\traceparamD \fi
   \ifx\end\next \let\nexts=\traceparamE \fi
   \ifx\nexts\undefined \let\nexts=\traceparamC\fi
   \nexts
}
\def\traceparamS{\addto\paramL{ }\afterassignment\traceparamA \let\next= }
\def\traceparamC#1{\addto\paramL{#1}\traceparamA}
\def\traceparamD#1{%
   \expandafter\addto\expandafter\paramL\expandafter
        {\expandafter\noexpand\csname ll:#1\endcsname}%
   \expandafter\def\csname ll:#1\endcsname{#1}%
   \traceparamA
}
\def\traceparamE\end{}

\def\smartuppercase#1{%
   \bgroup 
   \traceparam{#1}%
   \MakeUppercase{\paramL}%
   \egroup
}

\DeclareFieldFormat{uppercase}{\smartuppercase{#1}}
\DeclareBibliographyDriver{book}{\printfield[uppercase]{title}}

\begin{document}
  \nocite{*}
  \printbibliography
\end{document}

我的结果:

姆韦

但应该是“圣保罗”。


编辑:

我不知道这是否有用:biblatex有一个\MakeSentenceCase命令可以按照我想要的方式工作,但它只会将句子中的第一个字母大写,其余字母则变为小写。我试图找到它的定义方式,以便也许我可以对大写命令执行类似操作,我认为这是相关的部分,但对我来说毫无意义。我假设mksc代表“使小写字母”,这就是我所能得到的。

\newrobustcmd*{\MakeSentenceCase}{%
  \@ifstar\blx@mksc@i\blx@mksc@ii}

\def\blx@mksc@i{%
  \ifdef\abx@field@langid
    {\xifinlist\abx@field@langid\blx@cmksc@lang
       {\blx@mksc@ii}
       {\@firstofone}}
    {\blx@mksc@ii}}

\long\def\blx@mksc@ii#1{%
  \begingroup
  \let\blx@tempa\@empty
  \let\blx@tempb\@empty
  \blx@mksc@init
  \protected@edef\@tempa{#1}%
  \expandafter\blx@mksc@parse\@tempa\blx@mksc@end}

\def\blx@mksc@init{%
  \blx@mkcp@init
  \def\blx@mkcp@nil{\noexpand\blx@mkcp@nil\noexpand}%
  \def\i{\blx@mkcp@nil\i}\def\j{\blx@mkcp@nil\j}%
  \def\do##1{%
    \ifx##1\relax
    \else
      \def##1{\blx@mkcp@nil##1}%
      \expandafter\do
    \fi}%
  \expandafter\do\@uclclist\relax}

\def\blx@mksc@parse{%
  \futurelet\@let@token\blx@mksc@eval}

\def\blx@mksc@eval{%
  \ifx\@let@token\blx@mksc@end
    \expandafter\blx@mksc@end
  \fi
  \ifx\@let@token\bgroup
    \expandafter\blx@mksc@group
  \fi
  \ifx\@let@token\@sptoken
    \expandafter\blx@mksc@space
  \fi
  \ifx\@let@token\blx@mkcp@nil
    \expandafter\blx@mksc@getone
  \fi
  \ifx\@let@token\blx@mkcp@iec
    \expandafter\blx@mksc@getiec
  \fi
  \ifx\@let@token\blx@mkcp@bbl
    \expandafter\blx@mksc@gettwo
  \fi
  \ifx\@let@token\blx@mkcp@sgl
    \expandafter\blx@mksc@gettwo
  \fi
  \ifx\@let@token\blx@mkcp@dbl
    \expandafter\blx@mksc@getthree
  \fi
  \if\noexpand\@let@token\relax
    \expandafter\blx@mksc@cs
  \fi
  \blx@mksc@other}

\def\blx@mksc@end#1\blx@mksc@end{%
  \blx@mksc@eject
  \let\blx@mkcp@nil\noexpand
  \let\blx@mkcp@iec\noexpand
  \let\blx@mkcp@bbl\noexpand
  \let\blx@mkcp@sgl\noexpand
  \let\blx@mkcp@dbl\noexpand
  \let\MakeUppercase\relax
  \let\MakeLowercase\relax
  \protected@edef\blx@tempa{\endgroup\blx@tempa}%
  \blx@tempa}

\long\def\blx@mksc@group#1\blx@mksc@other#2{%
  \futurelet\@let@token\blx@mksc@ingroup#2&{#2}%
  \blx@mksc@endhead
  \blx@mksc@parse}

\long\def\blx@mksc@ingroup#1&#2{%
  \if\noexpand\@let@token\relax
    \blx@mksc@locase{{#2}}%
  \else
    \blx@mksc@nocase{{#2}}%
  \fi}

\def\blx@mksc@space{\def\blx@mksc@space##1\blx@mksc@other}
\csuse{blx@mksc@space} {%
  \blx@mksc@anycase{ }%
  \blx@mksc@endhead
  \blx@mksc@parse}

\long\def\blx@mksc@cs#1\blx@mksc@other#2{%
  \ifcat\noexpand~\noexpand#2%
    \blx@mksc@locase{#2}%
  \else
    \blx@mksc@nocase{#2}%
  \fi
  \blx@mksc@endhead
  \blx@mksc@parse}

\def\blx@mksc@getiec#1\blx@mksc@other#2#3#4{%
  \blx@mksc@other{#2#3{#4}}}

\def\blx@mksc@getone#1\blx@mksc@other#2#3{%
  \blx@mksc@other{#2#3}}

\def\blx@mksc@gettwo#1\blx@mksc@other#2#3#4{%
  \blx@mksc@other{#2#3#4}}

\def\blx@mksc@getthree#1\blx@mksc@other#2#3#4#5{%
  \blx@mksc@other{#2#3#4#5}}

\long\def\blx@mksc@other#1{%
  \blx@mksc@locase{#1}%
  \blx@mksc@endhead
  \blx@mksc@parse}

\def\blx@mksc@locase{%
  \appto\blx@tempb}

\def\blx@mksc@nocase{%
  \blx@mksc@eject
  \appto\blx@tempa}

\def\blx@mksc@anycase{%
  \ifx\blx@tempb\@empty
    \expandafter\appto
    \expandafter\blx@tempa
  \else
    \expandafter\appto
    \expandafter\blx@tempb
  \fi}

\def\blx@mksc@eject{%
  \ifx\blx@tempb\@empty
  \else
    \eappto\blx@tempa{\noexpand\MakeLowercase{\expandonce\blx@tempb}}%
    \let\blx@tempb\@empty
  \fi}

\def\blx@mksc@endhead{%
  \ifx\blx@tempb\@empty
  \else
    \eappto\blx@tempa{\noexpand\MakeCapital{\expandonce\blx@tempb}}%
    \let\blx@tempb\@empty
  \fi
  \let\blx@mksc@endhead\relax}

答案1

也许你需要这样的东西:

\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}

\def\traceparam#1{\def\paramL{}\traceparamA #1\end}
\def\traceparamA{\futurelet\next\traceparamB}
\def\traceparamB{%
   \let\nexts=\undefined
   \expandafter\ifx\space\next \let\nexts=\traceparamS \fi
   \ifx\bgroup\next \let\nexts=\traceparamD \fi
   \ifx\end\next \let\nexts=\traceparamE \fi
   \ifx\nexts\undefined \let\nexts=\traceparamC\fi
   \nexts
}
\def\traceparamS{\addto\paramL{ }\afterassignment\traceparamA \let\next= }
\def\traceparamC#1{\addto\paramL{#1}\traceparamA}
\def\traceparamD#1{%
   \expandafter\addto\expandafter\paramL\expandafter{\csname ll:#1\endcsname}%
   \expandafter\def\csname ll:#1\endcsname{#1}%
   \traceparamA
}
\def\traceparamE\end{}

\def\smartuppercase#1{%
   \bgroup 
   \traceparam{#1}%
   \uppercase\expandafter{\paramL}%
   \egroup
}

\smartuppercase{an Introduction to {TeX}}

编辑:如果重音字符有问题,那么你可以尝试\uppecase\MakeUpercase这样的方式替换

%\uppercase\expandafter{\paramL}%
\MakeUppercase{\paramL}

并且您必须像这样保护生成的 csnames:

%\expandafter\addto\expandafter\paramL\expandafter{\csname ll:#1\endcsname}%
\expandafter\addto\expandafter\paramL\expandafter
   {\expandafter\noexpand\csname ll:#1\endcsname}%

相关内容