5

My goal is to have different headers and sortings depending on a list of numbers.

I have multiple projects ordered by project number (desc). Now I want to highlight some projects, so that the highlights come first and then the other projects. Highlights still ordered by number and also the other projects.

If I have only highlighted projects or no one highlighted the header should be "Projects". If I have one or more highlighted projects the header should be "Highlighted projects" and for the projects which are not highlighted the header "Other projects".

My code for the projects without any highlighting looks like:

\xdef\myHighlights{ 01,03 }   
\let\mylist\empty
    \foreach\x in {00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, ...,20} {
      \ifx\mylist\empty 
        \xdef\mylist{\x}%
      \else
        \xdef\mylist{\x,\mylist}%
      \fi
    }

\foreach\x in \mylist {% \edef\projectNumber{\x}% \edef\FileName{path/to/project_\x}%
\IfFileExists{\FileName}{% \newpage% \input{\FileName}% }
}

I have to split \mylist into \normalProjectList and \highlightedProjectList. But I don't know how to compare if \x in \mylist is in \myHighlights.

2 Answers2

4

Here I use listofitems to search for each element of \myList in the \myHighlights list, and build the two requested (highlighted and normal) lists accordingly.

\documentclass{article}
\usepackage{listofitems}
\def\myHighlights{01,03}   
\def\myList{00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15,
  16, 17, 18, 19, 20}
\begin{document}
\newcommand\normalProjectList{}
\newcommand\highlightedProjectList{}
\readlist*\tlist{\myList}
\foreachitem\z\in\tlist[]{%
  \expandafter\setsepchar\expandafter{\z}%
  \readlist*\hlist{\myHighlights}
  \ifnum\listlen\hlist[]>1\relax
    \xdef\highlightedProjectList{\highlightedProjectList \z, }%
  \else
    \xdef\normalProjectList{\normalProjectList \z, }%
  \fi
}
Highlighted Projects:

\highlightedProjectList

Normal Projects:

\normalProjectList \end{document}

enter image description here

2

I'd set up an interface for the job.

The main command is \loadprojects that takes as arguments the first project number and the last one (missing numbers will not be a problem).

With \highlightprojects you state which ones you want highlighted (here you specify the precise termination).

If you do \loadprojects* then all projects are considered highlighted and \sethighlights is ignored.

You can specify the format of the numbers with the optional argument (default 2); so

\loadprojects[3]{0}{3}

would try and load the projects numbered 000, 001, 002 and 003.

In the example below I do \loadprojects with different settings of \sethighlights. First a couple of them are highlighted, then none, then all of them.

The available files are ramona00.tex, ramona01.tex, ramona02.tex, ramona03.tex and ramona05.tex (number 04 is missing).

\documentclass{article}
\usepackage[a6paper]{geometry} % to make smaller pictures
\usepackage{fancyhdr}

\fancyhf{} \fancyhead[R]{\projecttype} \fancyfoot[C]{\thepage} \pagestyle{fancy}

\ExplSyntaxOn

\NewDocumentCommand{\sethighlights}{m} { \seq_gset_from_clist:Nn \g_ramona_project_highlights_seq { #1 } }

\NewDocumentCommand{\setprojectroot}{m} { \tl_gset:Nn \g_ramona_project_root_tl { #1 } }

\NewDocumentCommand{\loadprojects}{sO{2}mm} {% #1 = * for all highlighted, % #2 = number of digits, % #3 = start point, % #4 = end point \ramona_project_load:nnnn { #1 } { #2 } { #3 } { #4 } }

\NewDocumentCommand{\projecttype}{} { \tl_use:N \l_ramona_project_header_tl }

\bool_new:N \g_ramona_project_all_highlighted_bool \tl_new:N \g_ramona_project_root_tl \tl_new:N \l_ramona_project_header_tl \seq_new:N \g_ramona_project_highlights_seq

\cs_new_protected:Nn \ramona_project_load:nnnn { % if all projects are highlighted or none is, set the conditional to true \bool_lazy_or:nnT { \bool_if_p:n { #1 } } % all highlighted { \seq_if_empty_p:N \g_ramona_project_highlights_seq } % none highlighted { \bool_gset_true:N \g_ramona_project_all_highlighted_bool } % now input the files \int_step_inline:nnn { #3 } { #4 } { \clearpage \bool_if:NTF \g_ramona_project_all_highlighted_bool {% all or no projects are highlighted \tl_set:Nn \l_ramona_project_header_tl { Projects } } {% check whether the current project is highlighted \seq_if_in:NxTF \g_ramona_project_highlights_seq { __ramona_projects_pad:nn { #2 } { ##1 } } % the current item {% the project is highlighted \tl_set:Nn \l_ramona_project_header_tl { Highlighted~Projects } } {% the project is not highlighted \tl_set:Nn \l_ramona_project_header_tl { Other~Projects } } } \file_if_exist_input:n { \g_ramona_project_root_tl __ramona_projects_pad:nn { #2 } { ##1 } } } }

\cs_new:Nn __ramona_projects_pad:nn { \prg_replicate:nn { #1 - \tl_count:n { #2 } } { 0 } #2 }

\ExplSyntaxOff

\setprojectroot{./ramona}

\begin{document}

\thispagestyle{empty} \begin{center} Only some are highlighted \end{center}

\sethighlights{00,02} \loadprojects{0}{5}

\clearpage

\thispagestyle{empty} \begin{center} None highlighted \end{center}

\sethighlights{} \loadprojects{0}{5}

\clearpage

\thispagestyle{empty} \begin{center} All are highlighted \end{center}

\loadprojects*{0}{5}

\end{document}

Some are highlighted

enter image description here

None is highlighted

enter image description here

All are highlighted

enter image description here

egreg
  • 1,121,712