0

I want to redefine \item[] to make it work like:

\documentclass[fontsize=22pt]{scrreprt}

\UsePackage[inline]{enumitem}
\newlist{notes}{description}{1}
\setlist[notes]{
  leftmargin=0.3\linewidth,labelsep=2em,
  itemsep=1.5ex,style=multiline,font=\normalfont
}

\def\removespecial{
  \catcode`\_=12
  \catcode`\^=12
  \catcode`\$=12
  \catcode`\%=12
  \catcode`\#=12
  \catcode`\&=12
  \catcode`\~=12
}

\begin{document}
\begin{notes}

\item[something]
{\removespecial\obeylines\obeyspaces
  ...some content...
}

\end{notes}
\end{document}

That is, to wrap the content after \item[] in parentheses so that I can use \obeylines etc inside. Without the parentheses, macros like \obeylines would affect the rest of the document and break some other commands. However, while manully adding the parentheses works, I can't figure out how to do it in macro (by redefining \item[] or some other ways). Can anyone show me how to do it?

  • @HarishKumar But this way it is still not wrapped? What is the \leavevmode for? – kawing-chiu Aug 16 '14 at 2:15
  • @HarishKumar That is to use parenthesis around \obeylines etc to limit its scope. {\obeylines sometext} makes \obeylines just affect sometext. – kawing-chiu Aug 16 '14 at 2:21
  • @HarishKumar No, it does affect the next item, just tested it. – kawing-chiu Aug 16 '14 at 2:58
  • Ok I take it back. No time for testing now. Hope somebody will pop up. :-) – user11232 Aug 16 '14 at 3:09
1

I haven't tested this extensively because I am not sure of your use case and your MWE doesn't give many clues. Still, I'm fairly confident that it works as you want because the MWE below produces:

enter image description here

In particular, note the spacing, line breaks and special characters that are behaving as you wanted. Moreover, given the comments above, I checked that your \remove@special doesn't remain in effect after the notes environment has closed, which is good.

The idea is to redefine \item inside a notes environment so that it inserts your special cat codes and \obey*'s inside a \bgroup...\egroup block. The first \item starts this group and the next one closes off the off the last group (using \endLastItem) and then starts the next \item-group. The only issue is that at the end of the notes environment we still need to close off the "special group" from the last \item. This is done by embedding your notes environment into another environment that takes care of this when is closes. So below the example actually appears inside a Notes environment.

Here's the code:

\documentclass[fontsize=22pt]{scrreprt}

\usepackage[inline]{enumitem}
\newlist{notes}{description}{1}
\setlist[notes]{
  leftmargin=0.3\linewidth,labelsep=2em,
  itemsep=1.5ex,style=multiline,font=\normalfont
}
\makeatletter
\def\remove@special{
  \catcode`\_=12
  \catcode`\^=12
  \catcode`\$=12
  \catcode`\%=12
  \catcode`\#=12
  \catcode`\&=12
  \catcode`\~=12
}
\let\realItem=\item
\let\endLastItem=\relax
\newcommand\specialItem[1][\relax]{\endLastItem%
   \ifx\relax#1\relax\realItem\else\realItem[#1]\fi%i
   \bgroup\remove@special\obeylines\obeyspaces
   \let\endLastItem\egroup}
\newenvironment{Notes}{\notes\let\item\specialItem}{\endLastItem\endnotes}
\makeatother

\begin{document}
  \begin{Notes}
    \item[something]
    \item Another     item with    some

    special commands # _ $ % & ~
  \end{Notes}
\end{document}
  • Hi! Thanks for the answer. It worked for the posted question. However, after posting this question, I realized that I was in a more complicated situation than the one formulated in this question. And the method you posted here not completely work for that situation. If you don't mind please also have a look at it and help me with that more complicated situation. – kawing-chiu Aug 18 '14 at 5:42

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.