I'm trying to check if a section number belongs to a specified list:
\ifnum\value{section}=\mylist % check if section number in mylist --- WRONG
\dosomething
\fi
The conditional is obviously wrong because it doesn't make sense to compare a number to a list. My sense is that there must be a quick fix (although my TeX knowledge is very limited). Please help!
p.s. Here's a more fully-spelled out version of the my question:
I'm trying to create an environment that can print selected sections only. I hope to specify in the beginning of the document a comma separated list of sections to be printed, and then print only selected sections. For example,
\keepsections{1,5,8}
\mysection{section 1}{content}
\mysection{section 2}{content}
\mysection{section 3}{content}
\mysection{section 4}{content}
\mysection{section 5}{content}
\mysection{section 6}{content}
\mysection{section 7}{content}
\mysection{section 8}{content}
Should give us:
This is what I've tried:
\documentclass{article}
\newcommand{\keepsections}[1]{ \newcommand{\mylist}{#1} }
\usepackage{environ}% http://ctan.org/pkg/environ
\NewEnviron{customsection}{ % new environment
\stepcounter{section} % environ should use the section counter
\ifcustomsec % if want to print only select sections from a list
\ifnum\value{section}=\mylist\relax % check if section in list --- WRONG
\addtocounter{section}{-1} % use correct counter and print
\BODY
\fi
\else % if want to print all sections,
\addtocounter{section}{-1} % use correct counter and print
\BODY
\fi%
}
\newcommand{\mys}[1]{\begin{customsection}#1\end{customsection}}
\newcommand{\mysection}[2]{\mys{\section{#1}#2}} % to conform to usage above
\newif\ifcustomsec % Boolean to print only selected sections
\customsectrue % Bool=True: Tell TeX to print only from the custom list
\keepsections{1,5,8} % Print only sections 1 and 3
\begin{document}
\mysection{section 1}{content}
\mysection{section 2}{content}
\mysection{section 3}{content}
\mysection{section 4}{content}
\mysection{section 5}{content}
\mysection{section 6}{content}
\mysection{section 7}{content}
\mysection{section 8}{content}
\end{document}
Although it fails because of the wrong logic pointed out above.
This question -- Create odd-numbered answers, or all answers -- has a very nice solution to printing just even or odd sections that works really well, and that's where I took the idea from.
This question -- Test if a number is in a comma separated range/list of numbers -- discusses defining a command of the sort
\ifinrange{<num>}{<range>}{<TRUE>}{<FALSE>}% num>=0
It would be nice if I could just replace
\ifnum\value{section}=\mylist\relax%
portion with
\ifinrange{\value{section}}{\mylist}{...}{...}
but with my limited knowledge I failed to implement it in this context.
Deeply appreciate any help. Thanks so much.