# Reorder sections based on a variable?

I have a CV I've created in LaTeX (using the moderncv package).

I'm trying to create flavors of the CV based on variables. What I would like to do is to generate the sections in a different order.

e.g. I currently have:

\section{Education}
\cventry{X}{Y}{Z}{}{}{}
\cventry{X}{Y}{Z}{}{}{}

\section{Experience}
\cventry{X}{Y}{Z}{}{}{}
\cventry{X}{Y}{Z}{}{}{}

\section{References}
\cventry{X}{Y}{Z}{}{}{}
\cventry{X}{Y}{Z}{}{}{}


So the PDF generated right now has this order:

• Education
• Experience
• References

I'd like, say, flavor_A to render as :

• Experience
• Education
• References

and flavor_B to render as:

• Experience
• Education

and flavor_C to render as:

• Education
• Experience
• References

Is something like this possible?

-
Welcome to Tex.SX! –  Umar Kalim Feb 17 '13 at 2:53

Without exploring more complex options, you could simply put each section in a separate file (say education.tex, experience.tex and references.tex) and include those in you main file (as Mariano correctly points out in his comment, using input is preferable to include in order to avoid page breaks):

\input{education.tex}
\input{experience.tex}
\input{references.tex}


Generating different flavors of your resume will then be a simple matter of reordering those three lines. To drop a section altogether, you can simply comment the line with %.

You could code a function to do the reordening based on a variable automatically (as your question suggested), but except if you are really going to generate lots and lots of flavors (which probably mean you should rethink your resume in my opinion), it's going to be less efficient than simply swapping the input lines.

-
\include tends to produce page breaks in the usual classes; '\input' doesn't. –  Mariano Suárez-Alvarez Feb 17 '13 at 5:00
My bad indeed; I've updated the answer accordingly. –  Xavier Feb 17 '13 at 5:46
Thank you, that works fine for me. I just need to keep/drop/change the order of some sections. –  hide0 Feb 17 '13 at 6:03
@hide0 To drop a section, you cans imply comment the line with %. I've added that to the answer. –  Xavier Feb 17 '13 at 16:28

In case splitting the CV into different files is unfeasible, here's a possibility: we absorb each section in a macro and use it when we want.

The example is drawn from the template in the documentation of moderncv.

\documentclass[11pt,a4paper,sans]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[scale=0.75]{geometry}
\setlength{\footskip}{40pt}
\moderncvstyle{casual}
\moderncvcolor{blue}

\usepackage{environ}
\makeatletter
% a helper macro

% the main environment
\NewEnviron{cvsection}[2][]{%
\if!#1!\def\cvsection@key{#2}\else\def\cvsection@key{#1}\fi
\global\@namedef{thecvsection@\cvsection@key}{\section{#2}}
}

% the command for printing the information
\newcommand{\usecvsection}[1]{\@nameuse{thecvsection@#1}}
\makeatother

% personal data
\firstname{John}
\familyname{Doe}
\title{Resumé title}
\mobile{+1~(234)~567~890}
\phone{+2~(345)~678~901}
\fax{+3~(456)~789~012}
\email{john@doe.org}
\homepage{www.johndoe.com}
%\photo[64pt][0.4pt]{picture}
\quote{Some quote}

\begin{document}
\makecvtitle

\begin{cvsection}{Education}
\end{cvsection}

\begin{cvsection}[MT]{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}
\end{cvsection}

\begin{cvsection}{Experience}
\subsection{Vocational}
\cventry{year--year}{Job title}{Employer}{City}{}{General description no longer than 1--2 lines.\newline{}%
Detailed achievements:%
\begin{itemize}%
\item Achievement 1;
\item Achievement 2, with sub-achievements:
\begin{itemize}%
\item Sub-achievement (a);
\item Sub-achievement (b), with sub-sub-achievements (don't do this!);
\begin{itemize}
\item Sub-sub-achievement i;
\item Sub-sub-achievement ii;
\item Sub-sub-achievement iii;
\end{itemize}
\item Sub-achievement (c);
\end{itemize}
\item Achievement 3.
\end{itemize}}
\cventry{year--year}{Job title}{Employer}{City}{}{Description line 1\newline{}Description line 2}
\subsection{Miscellaneous}
\cventry{year--year}{Job title}{Employer}{City}{}{Description}
\end{cvsection}

\usecvsection{Education}
\usecvsection{Experience}
\usecvsection{MT}

\end{document}


Each section appears in a cvsection environment that has an optional argument which should be used in case the section title does not consist only of plain ASCII characters. I've used it for "Master Thesis" although it wouldn't be necessary in this case.

After defining the various sections, you can print them in the order you prefer, using the section title or the key if the optional argument has been used for a particular section.

-
Thanks, this looks useful as well! I don't think I need it for this, but I'm pretty sure I have some other documents I can simplify with something like this :) –  hide0 Feb 17 '13 at 23:36