Re: Catturare e formattare la prima parola di una frase

#60845
Up
0
Down
::

Salve a tutti, ho il seguente problema:
ho una sequenza di parole (separate da spazi) ;
la sequenza va stampata in corsivo
e prima parola va stampata anche in grassetto.

Vorrei poter avere un comando tale che
`
\newcommand{\mytext}{\itshape This has to be tested}
\fmtfirsttoken{\bfseries}{\mytext}
`
restituisca:
This has to be tested

Come si potrebbe implementare una macro come \fmtfirsttoken ?

Ciao,
Agostino

`\documentclass[a4paper]{article}

\makeatletter
\def\fmtfirsttoken#1#2{\expandafter\@fmtfirsttoken\expandafter#1#2 \@nil}
\def\@fmtfirsttoken#1#2 #3\@nil{\itshape
{#1#2}\if\relax\detokenize{#3}\relax
\else\space#3\unskip\fi}
\makeatletter

\newcommand{\mytext}{This has to be tested}

\begin{document}
\fmtfirsttoken{\bfseries}{\mytext}X

\renewcommand{\mytext}{Ciao}
\fmtfirsttoken{\bfseries}{\mytext}X
\end{document}`
Ciao
Enrico

Go to top