1

I have the following code in my .cls file for my resume.

    \newenvironment{rSubsection}[4]{ % 4 input arguments - company name, year(s) employed, job title and location
     {\bf #1} \hfill {#2} % Bold company name and date on the right
     \ifthenelse{\equal{#3}{}}{}{ % If the third argument is not specified, don't print the job title and location line
      \\
      {\em #3} \hfill {\em #4} % Italic job title and location
      }\smallskip
      \begin{list}
      {$\cdot$}{\leftmargin=1.0em} % \cdot used for bullets, no indentation
       \itemsep -0.5em \vspace{-0.5em} % Compress items in list together for aesthetics
      }{
      \end{list}
      \vspace{0.5em} % Some space after the list of bullet points
    }

Note the \begin{list}. This expects a \item in the latex file. Failing to provide an \item throws the following error:

LaTeX Error: Something's wrong--perhaps a missing \item.

How can make having a list optional?

1

The following uses two packages to get around your requirement:

  • environ provides the means to capture the body of an environment inside a macro \BODY. This way we can rewrite each environment as a macro, which is sometimes easier when wanting to manage the content between \begin and \end.

  • etoolbox provides \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}. I've used it to replace \item with \item (effectively doing nothing) with the \BODY of the environment and allows one to condition on whether or not this replacement is <success>ful or not.

enter image description here

\documentclass{article}

\usepackage{etoolbox,environ}

\NewEnviron{rSubsection}[4]{% 4 input arguments - company name, year(s) employed, job title and location
  {\bfseries #1} \hfill #2 % Bold company name and date on the right
  % https://tex.stackexchange.com/q/263733/5764
  \if\relax\detokenize{#3}\relax\else % If the third argument is not specified, don't print the job title and location line
    \par
    {\itshape #3 \hfill #4} % Italic job title and location
  \fi\par\smallskip
  % \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
  \patchcmd{\BODY}{\item}{\item}{%
    \list
      {$\cdot$}
      {\leftmargin=1.0em % \cdot used for bullets, no indentation
      \itemsep -0.5em \vspace{-0.5em}} % Compress items in list together for aesthetics
      \BODY
    \endlist
  }{}%
  \vspace{0.5em} % Some space after the list of bullet points
}

\begin{document}

\begin{rSubsection}{First}{Second}{Third}{Fourth}
  \item First item
  \item Second item
  \item Third item
  \item Last item
\end{rSubsection}

\begin{rSubsection}{First}{Second}{}{Fourth}
  \item First item
  \item Second item
  \item Third item
  \item Last item
\end{rSubsection}

\begin{rSubsection}{First}{Second}{Third}{Fourth}
\end{rSubsection}

\end{document}

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.