这个问题允许我创建一个大写命令,该命令将忽略括号中的内容,因此将\smartuppercase{An introduction to {LaTeX}}
其打印为“LaTeX 简介”。
现在我想要一个命令,它可以做同样的事情,但会将文本同时转换为小写和小写。我试过这个:
\begin{filecontents}{\jobname.bib}
@book{blabla,
title = {An introduction to {LaTeX}}}
\end{filecontents}
\documentclass{article}
\usepackage[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{\addto\paramL{\textrm{#1}}\traceparamA}% This doesn't work either
\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\smartsc#1{%
\bgroup
\traceparam{#1}%
\textsc{\MakeLowercase{\paramL}}%
\egroup
}
\DeclareFieldFormat{uppercase}{\smartsc{#1}}
\DeclareBibliographyDriver{book}{\printfield[uppercase]{title}}
\begin{document}
\smartsc{An introduction to {LaTeX}}
\nocite{*}
\printbibliography
\end{document}
结果是这样的:
因此大写字母得以保留,并且“LaTeX”以大写字母 L、T 和 X 打印。但是 A 和 E 是小写字母,而我希望它们是常规小写字母。在针对我上面提到的问题的评论中@wipet (谢谢!) 建议我尝试traceparamD
用注释掉的代码替换,但仍然不起作用……如果我这样做,所有内容仍然会以小写形式显示,并且大写字母也不会保留:
有什么想法可以让我在该字符串中保留“LaTeX”与输入时一样,并使用相同的大写字母和常规字体(无小写字母)?
答案1
像这样?
\begin{filecontents}{\jobname.bib}
@book{blabla,
title = {An introduction to {LaTeX}}}
\end{filecontents}
\documentclass{article}
\usepackage[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{\normalfont #1}%
\traceparamA
}
\def\traceparamE\end{}
\def\smartsc#1{%
\bgroup
\traceparam{#1}%
\textsc{\MakeLowercase{\paramL}}%
\egroup
}
\DeclareFieldFormat{uppercase}{\smartsc{#1}}
\DeclareBibliographyDriver{book}{\printfield[uppercase]{title}}
\begin{document}
\smartsc{An introduction to {LaTeX}}
\nocite{*}
\printbibliography
\end{document}