3

I am new to Latex and am wondering if there exists anything like a class in HTML. I have been writing a bunch of documents lately and all my \items have needed to be italized, is there some way to indicate at the beginning of the file how to style \items without have to do:

\item \texit{.........................} 
\item \texit{.........................} 
\item \texit{.........................} 
\item \texit{.........................} 
\item \texit{.........................} 
\item \texit{.........................} 

over and over again?

  • There is nothing like a class in HTML, since there is no DOM. But there are ways to customize list environments to italicize the body of each list item. – Matthew Leingang Apr 22 '13 at 15:25
  • @MatthewLeingang Thanks, I was just trying to find a good analogous example. Could you point me to the package or an example of customizing list items ? – Hunter McMillen Apr 22 '13 at 15:34
  • the enumitem package is pretty handy for lists – Sean Allred Apr 22 '13 at 15:42
  • Oh! and Welcome to TeX.sx! – Sean Allred Apr 22 '13 at 15:43
  • @SeanAllred Thanks, I just looked at the docs for that package, seems to be exactly what I was looking for. – Hunter McMillen Apr 22 '13 at 15:46
3

You can redefine the behaviour of the itemize environment directly, exploiting the fact that \begin{itemize} calls the macro \itemize within a \begingroup ... \endgroup pair.

Example code

\setlength\parindent{0ex}
\let\originalitemize\itemize

\def\itemize{\originalitemize\itshape}
Some text
\begin{itemize}
\item foo \emph{(bar)} \item bar
\end{itemize}
Some text
\def\itemize{\originalitemize\scshape}
\begin{itemize}
\item foo \emph{(bar)} \item bar
\end{itemize}
Some text

In the above code, we use \let\originalitemize\itemize to save the meaning of the original \itemize macro, to allow us to make use of the original meaning when we customize the behaviour of itemize environments. This example shows two overriding customizations with different typefaces.

Result

Result of sample code

Note that because the typeface which we declare for \itemize is contained within a \begingroup ... \endgroup pair, the change in typeface doesn't extend any further than the environment. (This also incidentially demonstrates how you can obtain blocks of non-italicized text, or more accurately, how to toggle between italicized and non-italicized text.)

  • Does this also put the labels in \scshape? – Matthew Leingang Apr 22 '13 at 17:55
  • @MatthewLeingang: I'm not sure what you mean. The second example of restyling itemize certainly does, or do you mean item labels if you make an \item[label]? (It does, if that's what you're asking; if one wanted to prevent this behaviour, one could also redefine \itemize so that it modifies the \item command.) – Niel de Beaudrap Apr 23 '13 at 14:30
  • I was asking if the second example puts the bullets in \scshape font. It seems to be true. Not that it's noticeable in this question, but if you wanted to, say, change the color of the item body, this method would also change the color of the bullets. – Matthew Leingang Apr 23 '13 at 18:19
2

Niel's answer is a good one for what you want to do. I was thinking more generally of the question: how to change the formatting of the body of an enumerate or itemize environment, without changing the item labels?

In order to do this, you have to switch the font commands on and off after each \item and before the next \item. The trouble is that \item takes an optional argument. So to make it work, patch the auxiliary macro \@item:

\documentclass{article}
\usepackage{etoolbox}
\usepackage{color}
\begin{document}

\setlength\parindent{0ex}

\makeatletter
\pretocmd{\@item}{\normalfont\normalcolor}
{\message{Patching of @item succeeded.}}
{\message{Patching of @item failed.}}
\apptocmd{\@item}{\scshape\color{red}}
{\message{Patching of @item succeeded.}}
{\message{Patching of @item failed.}}

\makeatother


\begin{itemize}
\item foo \emph{(bar)} \item bar
\end{itemize}
Some text

\begin{enumerate}
\item foo
\item bar
\end{enumerate}

\end{document}

So when TeX encounters \@item, it will:

  1. switch the font and color (back) to \normal
  2. do what \@item would normally do, which is to set a label and change the margins, etc.
  3. switch the font to \scshape and color to red.

Here is the output:

sample code output

1

What about \def\ititemize{\begin{itemize}\itshape}?

  • This works, but makes everything in the item italicized, I have blocks of text after the \item that I would like to keep normal, is there any way to do that ? – Hunter McMillen Apr 22 '13 at 15:42
  • \textrm{your block}. But I don't know the percentage of normal text. – Przemysław Scherwentke Apr 22 '13 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.