I am trying to make a new function, to make my life simpler. The code is supposed to make a pagebreak and ouput a colored box at the next page. Aswell as puting something in the TOC
The code works, but not while inside of a command. Does anyone know how to do this?
The ultimate setup would be a command like this
\DEL{1}
producing
\newpage
\phantomsection
\addcontentsline{toc}{section}{{\color{red}\Large{Del 1}}}
\fcolorbox{black}{LightSteelBlue}{\parbox[t][1.25cm][c]{\textwidth}
{\begin{center}\textbf{Del 1 \\Uten hjelpemiddler}\end{center}}} }
and
\Del{2}
Producing
\newpage
\phantomsection
\addcontentsline{toc}{section}{{\color{red}\Large{Del 2}}}
\fcolorbox{black}{LightSteelBlue}{\parbox[t][1.25cm][c]{\textwidth}
{\begin{center}\textbf{Del 1 \\Uten hjelpemiddler}\end{center}}} }
I tried to make a new command like
\newcommand{\Del}{
\newpage
\phantomsection
\addcontentsline{toc}{section}{{\color{red}\Large{Del 2}}}
\fcolorbox{black}{LightSteelBlue}{\parbox[t][1.25cm][c]{\textwidth}
{\begin{center}\textbf{Del 1 \\Uten hjelpemiddler}\end{center}}} }
}
Alas this gives me some strange error, that I have not yet begun my document.
Now, I think it is all of the commands such as newpage latex does not want inside of a command. Looking forward to see your clever ideas, to solve this problem =)
Now, thanks to the effort below. I was able to discover what I was looking for an almost solve it.
Now this function is ment to be used on tests and exams as a header. "Uten hjelpemidler" means without any assistance/tools. Just pen and paper.
While "Med hjelpemiddler" is with all tools avaible, computer calculator etc. Now the function below is supposed to count each time I use such a header and count up. The input argument is for saying wheter the section is with or without calculator.
The problem is that the counter "tittel" gives an error when placed inside of the function. Anyone know how to fix this ? =)
\documentclass[border=5pt,tightpage]{standalone}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{xstring}
\newcounter{tittel}
\renewcommand{\thetittel}{\arabic{tittel}}
\newcommand{\tittel}{\stepcounter{tittel} \thetittel }
\setcounter{tittel}{0}
\newcommand{\Del}[1]{%
\IfStrEqCase{#1}{%
{u}{\def\Label{Uten }}%
{m}{\def\Label{Med }}%
}[\def\Label{UNKNOWN}]%
% \newpage
\phantomsection
\addcontentsline{toc}{section}{%
\protect\textcolor{red}{\protect\Large{Del \tittel }}}
\noindent\fcolorbox{black}{LightSteelBlue}{%
\parbox[t][1.25cm][c]{\dimexpr\textwidth-2\fboxsep-2\fboxrule}{
\centering\bfseries Del \tittel \\ \Label hjelpemider}%
}%
}
\begin{document}
Del{u}
Del{m}
Del{u}
\end{document}
Removing the \ infront of tittel, makes the command run. So adding a counter inside the command makes it fail =(
Del
is supposed to accept parameters the number of these need to be specified as[2]
. Then you access them as#1
,#2
. You should also add a%
and the end of each line.}
moren then opening{
. Can you provide the error message you get and a MWE?