% Copyright 2019-2021 The LaTeX Project

\providecommand*{\lastissue}{12}

\documentclass{ltnews}

\AtBeginDocument{%
  \renewcommand{\LaTeXNews}{\LaTeX3~News}%
  \RaggedRight
  \setlength\parindent{1em}%
}
\usepackage{catchfile}
\usepackage{csquotes}
\usepackage{enumitem}
\usepackage{fancyvrb}
\usepackage{hologo}
\usepackage{metalogo}
\usepackage{multicol}
\usepackage{ragged2e}
\usepackage{siunitx}
\usepackage{tikz}
\usepackage{underscore}
\usepackage{xparse}
\usepackage{hyperref}
\hypersetup{colorlinks}
\usepackage{bookmark}

\MakeOuterQuote{"}

\pdfstringdefDisableCommands
  {%
    \RenewExpandableDocumentCommand \cs { O{} m }
      {\textbackslash#2}%
  }

\makeatletter
\newcounter{issue}
\renewcommand*{\theissue}{%
  \ifnum\value{issue}<10 0\fi
  \number\value{issue}%
}
\newcommand*{\MonthJanuary}{01}
\newcommand*{\MonthFebruary}{02}
\newcommand*{\MonthMarch}{03}
\newcommand*{\MonthApril}{04}
\newcommand*{\MonthMay}{05}
\newcommand*{\MonthJune}{06}
\newcommand*{\MonthJuly}{07}
\newcommand*{\MonthAugust}{08}
\newcommand*{\MonthSeptember}{09}
\newcommand*{\MonthOctober}{10}
\newcommand*{\MonthNovember}{11}
\newcommand*{\MonthDecember}{12}
\newcommand*{\printissue}{%
  Issue %
  \texorpdfstring{\number\value{issue}}{\theissue}, %
  \texorpdfstring{\@month\space\@year}{\@year/\@nameuse{Month\@month}}%
}
\let\l@part\l@section
\let\l@section\l@subsection
\let\l@subsection\l@subsubsection
\let\l@subsubsection\l@paragraph
\let\l@paragraph\l@subparagraph
\newcommand*{\makefirsttitle}{%
  \twocolumn[{%
    \parbox[t][4\baselineskip]{\textwidth}{%
      \@titlefont\@title, Issues 1--\lastissue
    }%
  }]%
}

% show the page number on first page of issues:

\renewcommand{\ps@titlepage}{%
   \renewcommand{\@oddhead}{\hfill}%
   \renewcommand{\@evenhead}{\hfill}%
   \renewcommand{\@oddfoot}{\@indiciafont\@indicia\hfill --\thepage}%
   \renewcommand{\@evenfoot}{\@indiciafont\@indicia\hfill --\thepage}%
}

% only needed if the old ltnews class is used
\renewcommand{\@oddfoot}{\@indiciafont\mbox{}\hfill --\thepage}%
\renewcommand{\@evenfoot}{\@indiciafont\mbox{}\hfill --\thepage}%


\makeatother

\begin{document}

%%% Title and Table of Contents

\makefirsttitle
\pdfbookmark[0]{\contentsname}{toc}
\tableofcontents
\clearpage

\begingroup
  \renewcommand*{\AtBeginDocument}[1]{#1}%
  \renewcommand*{\PassOptionsToPackage}[2]{}%
  \renewcommand*{\usepackage}[2][]{}%
  \renewcommand*{\RequirePackage}[2][]{}%
  \renewcommand*{\documentclass}[2][]{%
    \setcounter{footnote}{0}%
    \gobbleopt
  }%
  \newcommand*{\gobbleopt}[1][]{}%
  \makeatletter
  \let\org@twocolumn\twocolumn
  \renewenvironment{document}{%
    \clearpage
    \ifnum\@issue=20 %
      \addtocontents{toc}{\protect\setcounter{tocdepth}{5}}%
      \addtocontents{toc}{%
        \protect\makeatletter
       }%
       \addtocontents{toc}{%
         \let\protect\saved@l@paragraph\protect\l@paragraph
       }%
       \addtocontents{toc}{%
         \let\protect\l@paragraph\protect\l@subsection
       }%
    \fi
    \ifnum\@issue>9\space  % we may have issue tocs ...
      \addtocontents{toc}{%
        \let\protect\l@paragraph\protect\saved@l@paragraph
      }%
      \def\toclevel@subsection{1}%
      \def\toclevel@subsubsection{2}%
      \addtocontents{toc}{\protect\setcounter{tocdepth}{4}}%
      \renewcommand*{\tableofcontents}{%
        \section*{\contentsname}%
        \@starttoc{toc\theissue}%
      }%
      \let\saved@addtocontents\addtocontents
      \renewcommand*{\addtocontents}[2]{%
        \saved@addtocontents{##1}{##2}%
        \def\temp@toc{toc}%
        \def\temp@param{##1}%
        \ifx\temp@toc\temp@param
          \saved@addtocontents{toc\theissue}{##2}%
        \fi
      }%
      \let\l@subsubsection\l@subsection
      \let\l@subsection\l@section
      \let\l@section\l@part
      \let\l@part\@gobbletwo
    \fi
    \def\twocolumn[{%
      \let\twocolumn\org@twocolumn
      \org@twocolumn[%
      {% because of optional argument of \twocolumn
        \pdfbookmark[0]{\printissue}{issue\theissue}%
      }%
      \begingroup
        \let\WriteBookmarks\relax
        \@firstofone{% inside opt. arg. of \twocolumn: protect "]"
          \renewcommand*{\Hy@writebookmark}[5]{}%
        }%
        \phantomsection
        \addcontentsline{toc}{part}{\printissue}%
      \endgroup
    }%
  }{%
    \clearpage
  }%
  \def\MakeOuterQuote#1{%
    \if\noexpand"\noexpand#1%
    \else
      \@latex@error{Unexpected \string\MakeOuterQuote
          {\detokenize{#1}}\MessageBreak%
        Check if output is valid in `l3news\theissue.tex'}%
    \fi}
  \makeatother
  \loop
  \ifnum\value{issue}<\lastissue
    \stepcounter{issue}%
    \input{l3news\theissue}%
  \repeat
  \stepcounter{issue}%
  \IfFileExists{l3news\theissue}{%
    \@latex@error{\jobname.tex is out of date,\MessageBreak
      there is `l3news\theissue.tex'%
    }\@ehc
  }{}%
\endgroup

\end{document}