1

I am trying to create my own report template. The idea is that users have only to enter variables and focus on the contents. I tried to create an altered titlepage but get an error, my testreport.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testreport}[2017/04/02 v0.1 test report template]
\LoadClassWithOptions{article}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

% for the title page
\newcommand*{\client}[1]{{#1}}
\newcommand*{\project}[1]{{#1}}

\renewcommand*{\maketitle}{
\begin{titlepage}
\title
\\
\project
\\
\client
\\
\date
\\
\author

\end{titlepage}
}

And I have the following in my .tex file:

\documentclass{testreport}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}

\title{Custom class example}
\author{Yorian}
\date{\today}
\project{aa}
\client{BB}

\begin{document}

% Create title page
\maketitle

\end{document}

But I get an error:

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.21 \maketitle

? 

I don't see what's going wrong here. Any suggestions?

Yorian
  • 135
  • \title, \author, and \date, as well as \project and \client, are all commands that take arguments. This doesn't seem to be the case in the template file, though. – Mico Apr 02 '18 at 13:15

1 Answers1

1

Two problems:

  • macros like \title{Custom class example} are there to input information. If you want to retrieve this information again, you need to call another macro in which the information is stored. For title this would be \@title, but you can create this also for your own fields.

  • don't misuse \\, see When to use \par and when \\, or blank lines

    \documentclass{article}
    
    \makeatletter
    \def\client#1{\gdef\@client{#1}}
    \def\@client{}
    
    \def\project#1{\gdef\@project{#1}}
    \def\@project{}
    
    \renewcommand*{\maketitle}{
        \begin{titlepage}
            \@title
    
            \@project
    
            \@client
    
            \@date
    
            \@author
    \end{titlepage}
    }
    
    \makeatother
    
    \usepackage{graphicx}
    \usepackage[utf8]{inputenc}
    
    \title{Custom class example}
    \author{Yorian}
    \date{\today}
    \project{aa}
    \client{BB}
    
    \begin{document}
    
    % Create title page
    \maketitle
    
    \end{document}
    
  • Thanks @samcarter. I thought that (based on this thread: https://tex.stackexchange.com/questions/655/what-is-the-difference-between-def-and-newcommand) that newcommand would be preferred over def. Also, you use makeatletter, I understand this allows you to use the @ symbol in variables, but you call it twice does close the scope? Also regarding \def, are square brackets around the variable numbers optional? – Yorian Apr 02 '18 at 14:30
  • @Yorian You're correct, the second \makeatletter should have been a \makeatother, but you don't need them if you use the code in a class file. I am not an expert for the comparison of newcommand/def etc, but it depends on the context. I choose \def to be consistent with how \title etc are most commonly defined. Maybe the \gdef is overkill .... – samcarter_is_at_topanswers.xyz Apr 02 '18 at 19:09