グループの最初の文字だけをタイプセットする

グループの最初の文字だけをタイプセットする

テキストグループの最初の文字だけをタイプセット(印刷)するにはどうすればよいでしょうか?

たとえば、名前の最初の文字はどのようbiblatexにして決定されるのでしょうか?bibtex

MWE を始めるには:

\documentclass[]{article}

\begin{document}

This prints \firstinit{just the first letter}.

My hero is \firstinit{John} \firstinit{Paul} Jones.

\end{document}

答え1

ルーチン\justfirstには引数が必要ですない中括弧で囲まれていますが、既知の値で終了しています。したがって、 は、ユーザーのテキストに表示される可能性が低いため、ユーザーには知られずに と\firstinit共謀して、 を終了文字として提供していることになります。\justfirst\relax

\documentclass[]{article}
\def\firstinit#1{\justfirst#1\relax}
\def\justfirst#1#2\relax{#1}

\begin{document}

This prints \firstinit{just the first letter}.

My hero is \firstinit{John} \firstinit{Paul} Jones.

\end{document}

ここに画像の説明を入力してください


もちろん、複数語のフレーズの最初の文字を出力する場合は、それぞれ単語は、少し難しくなります。再帰を利用するために改訂されました。パッケージの使用を排除するために再改訂されました。「ラマ」による敗北を防ぐために再再改訂されました。

\documentclass[]{article}
\def\firstinit#1{\justfirst#1 \relax\relax}
\def\justfirst#1#2 #3\relax{#1\if\relax#3\else{} \justfirst#3\relax\fi}
\begin{document}
This prints \firstinit{just the first llama in the list}.

My hero is \firstinit{John} \firstinit{Paul} Jones.
\end{document} 

ここに画像の説明を入力してください

関連情報