Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to redefine an enumerate environment that would look something like this in use:

\begint{customItemize}
\item $-6x^{2}-2x=-2x(3x+1)$
\item $-5x+15=-5(x-3)$
\end{customItemize}

And be equivalent to something like this

\begin{enumerate}
\item \fbox{$-6x^{2}-2x=-2x(3x+1)$}
\item \fbox{$-5x+15=-5(x-3)$}
\end{enumerate}

In addition to \fbox, I might like to be able to use other (custom) commands. It is important that this happens within the environment, so that the

\item Some stuff
\item Some more stuff 

part of the code is easily copy/pasted to other list environments.

Can this be done?

I've tried something like this, but it's not working and I think it is because I don't know how to deal with parameters of \item.

\newenvironment{customItemize}{%
                \let\olditem\item% 
                \renewcommand\item[2]{ \olditem\fbox{##2} }%
                \begin{enumerate}}{\end{enumerate}%
}

Math mode is breaking somehow within fbox... but I'm kinda clueless as to how to proceed. Again, I think it is something that I don't understand about the "arguments" for \item

share|improve this question
1  
Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Feb 21 '13 at 15:19
add comment

migrated from stackoverflow.com Feb 21 '13 at 14:15

This question came from our site for professional and enthusiast programmers.

1 Answer

The problem isn't with the math mode. It is with the fbox. The way \item traditionally works is to put some sort of identifying blivet at the head of the line, and then the text that follows the \item is printed. But to use an fbox, you need all of that text to be an argument to \fbox, meaning, enclosed in braces {}. Without the braces, only a the first character of the text is taken as the argument to \fbox, which is not what you want. (I also corrected a typo in your environment definition). So, the way to do it is enclose the text of the item in braces {}. This will make your environment work, and (while non-standard) won't break from being copied and pasted into another environment. I show it below, with both items (non-math and math) being placed first in your environment, and then in the normal itemize environment.

\documentclass{article}
\newenvironment{customItemize}{%
                \let\olditem\item% 
                \renewcommand\item[1]{ \olditem\fbox{##1} }%
                \begin{enumerate}}{\end{enumerate}%
}

\begin{document}
Here we go
\begin{customItemize}
\item {Testing}
\item {$y = x^2$}
\end{customItemize}

\begin{itemize}
\item {Testing}
\item {$y = x^2$}
\end{itemize}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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