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 working on a custom .cls for typesetting my CV. I am trying to create a custom environment to provide formatting for job/education history. I would like to specify it as follows:

\begin{cvsection}
  \cvdate{xx-xx-xxxx}
  \cvcompany{Some company & Co.}
  \cvposition{Toilet cleaner}
  \cvcomment{I love cleanin' dem toilets!}
\end{cvsection}

So I've defined my environment and tried to use \newcommand... within the environment definition. LaTeX doesn't like that so what is the best way to approach this?

share|improve this question
    
Welcome to TeX.sx! Please add a complete minimal working example (MWE) that illustrates your problem. With your code snippet and no concrete error message we can only guess what "LaTeX doesn't like it" mean. –  Kurt Oct 10 '12 at 14:00
    
@Kurt Thanks for the welcome. So far I have this: \newenvironment{cvsection}{\newcommand{\cvdate}[1]{\bf #1\\}...}{} –  bugsduggan Oct 10 '12 at 14:08

1 Answer 1

up vote 9 down vote accepted

One purpose of organizing an environment in that way is to allow flexibility in the input.

You don't need to define the commands inside the environment; a frequently used strategy is the following:

\newcommand{\cvdate}[1]{\renewcommand{\givencvdate}{#1}}
\newcommand{\cvcompany}[1]{\renewcommand{\givencvcompany}{#1}}
\newcommand{\cvposition}[1]{\renewcommand{\givencvposition}{#1}}
\newcommand{\cvcomment}[1]{\renewcommand{\givencvcomment}{#1}}
\newcommand{\givencvdate}{REQUIRED!}
\newcommand{\givencvcompany}{REQUIRED!}
\newcommand{\givencvposition}{REQUIRED!}
\newcommand{\givencvcomment}{} % this is optional

\newenvironment{cvsection}
 {\begin{flushleft}}
 {\textbf{\givencvdate}\\
  \givencvcompany\\
  \givencvposition
  \ifx\empty\givencvcomment\else\\[.5ex] \textit{\givencvcomment}\fi
  \end{flushleft}}

In this way the order one specifies the data in the environment is irrelevant. Let's see a couple of examples

\begin{cvsection}
  \cvdate{xx-xx-xxxx}
  \cvcompany{Some company \& Co.}
  \cvposition{Toilet cleaner}
  \cvcomment{I love cleanin' dem toilets!}
\end{cvsection}

\begin{cvsection}
  \cvposition{Toilet cleaner}
  \cvdate{xx-xx-xxxx}
  \cvcompany{Another company \& Co.}
\end{cvsection}

Of course you have to adjust the definition of cvsection to suit your needs.

enter image description here

share|improve this answer
    
basically I was doing it wrong (which was what I thought). Thank-you. –  bugsduggan Oct 10 '12 at 14:37
1  
@bugsduggan You can define the commands in the environment, so that they can't be used outside. Just move the block of definitions in the "beginning" part of cvsection (between { and \begin{flushleft}) but remember to write ##1 instead of #1. –  egreg Oct 10 '12 at 14:43

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.