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'm new to creating new environments and even though I searched at the xparse*documentation I couldn't figured out how to solve my specific problem. I would like to create a new environment, say concept, and I would like it to take an optional argument (I don't know if it has to be a boolean or what). This optional argument will make the text to be in italics. If the argument is not declared, it will simply print normal font. It's as simple as that. So

\begin{concept}[i] % I just invented a option named "i"
  This text will be in italics
\end{concept}

or without an option

\begin{concept}
  This text will be in normal font.
\end{concept}

I thought that may be using the xparse package would make the task easier. Sorry to ask such a silly question but I couldn't come to a solution.

share|improve this question
    
For simple usages see Peter's answer. For advanced stuff, try some of the keyval packages like kvoptions or pgfkeys, xkeyval, l3keys etc. –  tohecz Feb 20 '13 at 13:31
    
Welcome to TeX.sx! Your post was migrated here from Stack Overflow site. 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 20 '13 at 15:21
add comment

migrated from stackoverflow.com Feb 20 '13 at 13:17

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

1 Answer

up vote 5 down vote accepted

Normal LaTeX environments can do this without the need for the xparse package:

enter image description here

Notes:

  • I have used the xstring package for string comparison as I prefer it's syntax, but this could be done without that package if needed.

References:

Relevant for using \itshape:

Code:

\documentclass{article}
\usepackage{xstring}

\newenvironment{concept}[1][]{%
    \IfStrEq{#1}{i}{\itshape}{}%
}{%
}%

\begin{document}
\begin{concept}[i]% I just invented a option named "i"
  This text will be in italics
\end{concept}

\begin{concept}
  This text will be in normal font.
\end{concept}

\end{document}
share|improve this answer
    
Thanks @peter ! –  ezitoc Feb 19 '13 at 19:11
add comment

Your Answer

 
discard

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