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:

  \cvcompany{Some company & Co.}
  \cvposition{Toilet cleaner}
  \cvcomment{I love cleanin' dem toilets!}

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?


1 Answer 1


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{\givencvcomment}{} % this is optional

  \ifx\empty\givencvcomment\else\\[.5ex] \textit{\givencvcomment}\fi

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

  \cvcompany{Some company \& Co.}
  \cvposition{Toilet cleaner}
  \cvcomment{I love cleanin' dem toilets!}

  \cvposition{Toilet cleaner}
  \cvcompany{Another company \& Co.}

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

enter image description here

  • basically I was doing it wrong (which was what I thought). Thank-you.
    – bugsduggan
    Oct 10, 2012 at 14:37
  • 2
    @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, 2012 at 14:43
  • @egreg How could it be done using LaTeX3 syntaxis? Do I still need to use the ##1 form?
    – Dox
    Apr 29, 2015 at 20:05
  • 1
    @Dox Yes, there's no difference in that respect: it's a TeX general fact. I see no real advantage in doing it in expl3 syntax, except perhaps the test about emptyness.
    – egreg
    Apr 29, 2015 at 20:54

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.