Like this?
\documentclass{article}
\usepackage{xcolor}
\newcommand{\sectioncolored}[3]{%
\section{\textcolor{#1}{#2} #3}%
}
\makeatletter
\def\entrylistsplitfirst#1 #2\@nil{#1}
\def\entrylistsplitsecond#1 #2\@nil{#2}
\newenvironment{entrylist}[2]{%
\edef\tempa{\expandafter\expandafter\expandafter\entrylistsplitfirst #2\@nil}%
\edef\tempb{\expandafter\expandafter\expandafter\entrylistsplitsecond #2\@nil}%
\sectioncolored{#1}{\tempa}{\tempb}%
}{}
\makeatother
\begin{document}
\begin{entrylist}{blue}{Blue Black}
abc
\end{entrylist}
\end{document}
Explanation
We need to pass \sectioncolored
3 arguments rather than 2: the colour; the first word; the remaining words. We then use \textcolor{#1}{#2}
to colour just the first word.
\newcommand{\sectioncolored}[3]{%
\section{\textcolor{#1}{#2} #3}%
}
We're going to use @
commands, so we need to change the catcode using \makeatletter
.
\makeatletter
We define \entrylistsplitfirst#1 #2\@nil
to get the first word of the title.
\def\entrylistsplitfirst#1 #2\@nil{#1}
We define \entrylistsplitsecond#1 #2\@nil
to get the remainder of the title.
\def\entrylistsplitsecond#1 #2\@nil{#2}
We need \def
because our parameter specification includes a space. The \@nil
is used to mark the end of the arguments. Note that these definitions assume that the title will have at least 2 words. If you might have a single-word title, you would need to adjust the code to accommodate this possibility as well.
We then define the environment.
\newenvironment{entrylist}[2]{%
First, we save the first word of the title into the macro \tempa
.
\edef\tempa{\expandafter\expandafter\expandafter\entrylistsplitfirst #2\@nil}%
Second, we save the rest of the title into the macro \tempb
.
\edef\tempb{\expandafter\expandafter\expandafter\entrylistsplitsecond #2\@nil}%
Finally, we pass the colour (#1
) and the two parts of the title off to \sectioncolored
. Note that I altered something here as the original code defined one macro and used another, which obviously won't work. (\sectioncolored
is not the same macro as \sectionColored
.)
\sectioncolored{#1}{\tempa}{\tempb}%
}{}
Finally, we restore @
to its usual status in the preamble.
\makeatother
Best Answer
The definition of
is wrong, at least the parts with
{ #1\\ }{...}
, which are surely meant as the real document body, not something outside after the{\par}
statement which is theend code
part of the environment.This way
#1 ...
etc. is meant as typesetting after the environment definition which must fail unless the definition is wrapped itself in another command or environment.