How can I change the text (not the label) for each item in an itemize environment using wrappers?

How can I customize the text (not the label) after each \item in an itemize environment?

I don't see any option for that in the enumitem package. Other questions on Tex StackExchange also seem to worry more about the label and spacing and not about the <text> in \item <text>. I hope I didn't miss anything. At least it doesn't seem trivial to me, but maybe I'm just looking in the wrong places...

The background is that I am trying to change the behavior of hyphenation in the beamer presentation as suggested by me in this answer. But with the solution I've proposed, you have to write \hy{} after each \item everywhere. The text is embedded in this command, so the option before and after from enumitem doesn't seem to work for me.

Isn't there a way to make this easier?

For example, all items here

\documentclass{beamer}
\def\examplecommand#1{\parbox{\linewidth}{#1}}
\begin{document}
\begin{frame}{}
\begin{itemize}
\item \examplecommand{I do not want to be wrapped each time}
\item \examplecommand{I do not want to be wrapped each time}
\item \examplecommand{I do not want to be wrapped each time}
\item \examplecommand{I do not want to be wrapped each time}
\end{itemize}
\end{frame}
\end{document}


should only be written as:

\item I do not want to be wrapped each time


without redundant \examplecommand{…}. Of course a new command instead of \item or a new environment instead of itemize is also possible. I just don't want to have so much redundancy.

I tried something like this, but adding

\newenvironment{hytemize}{%
\let\olditem\item%
\renewcommand\item[2][]{\olditem ##1 \examplecommand{##2}}%
\begin{itemize}}{\end{itemize}%
}


and renaming itemize to hytemize leads to weird results.

Update:

I also don't want to write extra curly brackets wrapping each element text, it should be the same as before, i.e. writing \item ... should be sufficient. The background to my request is indeed to reactivate the hyphenation of beamer, but I am also interested in a general solution to change the text after an \item, and the writer should then not have to worry about this change, e.g. by writing curly brackets instead of none.

Update 2:

This comment finally answers my update.

• using a parbox to enable hyphenation is rather odd... you just need a single declaration changing \raggedright back to the default justification (the only part of the parbox definition you need) or RaggedRight as suggested in the other answer to the linked question. – David Carlisle Apr 26 at 15:55
• If all you want to achieve is re-enable hyphenation in an itemize environment, you shouldload the ragged2e package and issue the directive \RaggedRight immediately after \begin{itemize}. No need to mess with the contents of each \item. – Mico Apr 26 at 16:04
• Thanks DavidCarlisle and Mico -- agree and that was very helpful, thx. Just leaving the question as it. I'm also interested in a more general approach manipulating a text after item. – colidyre Apr 26 at 17:28

I get the impression that what you're really trying to achieve by placing the arguments of \item directives in a \parbox is to re-enable hyphenation. If this impression is correct, i.e., if the main objective is hyphenation-related, there's a far simpler solution: Load the ragged2e package and issue the directive \RaggedRight immediately after \begin{itemize} (or \begin{enumerate}).

\documentclass{beamer}
\usepackage[ngerman]{babel}
\usepackage{ragged2e}
\begin{document}

\begin{frame}[t]
\begin{itemize} \RaggedRight
Donaudampfschifffahrtsgesellschaftsmitarbeiters
Rechtsschutzversicherungsgesellschaftsvertrag
sechshundertsechsundsechzigtausendzweihundertsiebenundachzig
\end{itemize}
\end{frame}
\end{document}

• This is right, I really want to achieve that, and setting \RaggedRight after each \begin{itemize} is doing the job. This is imo the simplest solution which can be generalized with \let\raggedright=\RaggedRight without having to write this command after each itemize environment and in addition, there is no need to wrap item text in curly braces (i.e. no change in standard behaviour which is also important for me). So thank you for this answer. But I am also interested in why it is so hard or how to use any wrappers \xy{…} correctly for item contents: \item … instead of \item \xy{…}? – colidyre Apr 27 at 9:41
• @colidyre - Regarding the question you pose: I don't have a concise answer. I suspect, though, that the issue arises because the LaTeX environments enumerate, itemize and description all depend on the low-level list environment which, in turn, depends on the even-lower-level trivlist environment. (The code for these environments is given in the LaTeX "kernel"; look for the file latex.ltx in your TeX distribution.) I suspect one would have to create a new list-like environment from scratch to achieve your formatting goals more directly. – Mico Apr 27 at 9:55
• Okay, that makes sense. This comment finally answers my question. Now I see my problems not finding a suitable solution for what I want. So it seems that due to the usage of low-level environments, I can't offer a general solution without writing a completely separate environment from scratch. – colidyre Apr 27 at 10:16

Is this okay? I just defined a new command.

\documentclass{beamer}

\def\examplecommand#1{\parbox{\linewidth}{#1}}
\newcommand{\newitem}[1]{\item \examplecommand{#1}}

\begin{document}
\begin{frame}{}
\begin{itemize}
\newitem{I do not want to be wrapped each time}
\newitem{I do not want to be wrapped each time}
\newitem{I do not want to be wrapped each time}
\newitem{I do not want to be wrapped each time}
\end{itemize}
\end{frame}
\end{document}

• Ah, this is helpful. Now I understand that my weird results coming from not using curly brackets. But also the curly brackets are very redundant. I am searching for a solution not using these. – colidyre Apr 26 at 17:10
• @colidyre the brackets are not redundant if you want to pass to \parbox as that means you have to grab the text as an argument, if you just need to set the line breaking parameters which is your real use case you only need to set that once for the whole environment and do not need to change \item at all. – David Carlisle Apr 26 at 17:12

I agree completely with David's and Mico's sentiment about better ways to introduce hyphenation. But since you also expressed an interest in creating a new environment that redefines \item to take an argument, here are the changes from what you tried:

1. Introduced [t] option to the \parbox.

2. Must make \examplecommand a \long\def or better still a \newcommand, since the \item argument may contain paragraph breaks.

3. Redefined \item after entering itemize.

The MWE:

\documentclass{beamer}
\long\def\examplecommand#1{\parbox[t]{\linewidth}{#1}}
\newenvironment{hytemize}{%
\let\olditem\item%
\begin{itemize}\renewcommand\item[2][]{\olditem ##1 \examplecommand{##2}}}{\end{itemize}%
}
\begin{document}
\begin{frame}{}
\begin{hytemize}
\item {I do not want to be wrapped each time. This should be longer
than one line

In addition, it can be two paragraphs.}
\item {I do not want to be wrapped each time}
\item {I do not want to be wrapped each time}
\item {I do not want to be wrapped each time}
\end{hytemize}
\end{frame}
\end{document}


• Cool! Thanks, this is a good improvement and explanation of what I've tried. But it's important for me, to not change the standard behaviour of \item. Here it's still the case that you have to write \item {…} (with curly brackets) instead of \item … (without, same as before). Now I understand that this is not easy to manage, because I'm using also parbox and the text after item is used as an argument for parbox. I'll try to improve my question... – colidyre Apr 27 at 9:57