9

I want to define some variable for my IPE template, such as the title, affiliation and author etc. The code is listed below. However when I compile it using pdflatex, it does not show the result what the \def variable should be. When I remove the \makeatletter and \makeatother, it issued a error message "! Use of \@ doesn't match its definition."

Any solutions ?

\documentclass{article}
\usepackage{color}

\makeatletter
\def\title#1{\def\@title{#1}} % Title 
\def\displaytitle#1{\def\@displaytitle{#1}} % Display Title
\def\displayauthor#1{\def\@displayauthor{#1}} % Display author
\def\displayaffiliation#1{\def\@displayaffiliation{#1}} % Display affiliation
\makeatother

\title{This is a presentation}%
\displayauthor{Liu Benyuan}%
\displayaffiliation{The Automatic Target Recognition (ATR) Laboratory}%
\displaytitle{Compressive Sensing via Block Sparse Bayesian Learning : Theory and Applications}%

\begin{document}

\begin{minipage}{736pt}
\vspace*{.5em}
\begin{minipage}{650pt}\Large
\textcolor{red}{
{\bf \@displayauthor{}}~~$\cdot$~~{\bf \@displayaffiliation{}}~\hfill$\cdot$\hfill~{\bf NUDT}} \\
\textcolor{blue}{
\bf \@displaytitle{}\hfill \today{}}
\end{minipage}
\hspace*{8em}
\vspace*{.5em}
\end{minipage}

\end{document}
  • 1
    Beside using \makeatletter before the minipage: You could also simply use command names without @. E.g. instead of \def\@displayaffiliation{#1} do \def\displayaffiliationcontent{#1}. – Ulrike Fischer Jun 26 '13 at 7:34
  • Welcome to TeX.SX! You can have a look on our our starter page to familiarize yourself further with our format. – Claudio Fiandrino Jun 26 '13 at 7:37
  • @ulrike Fischer, Yes, your method can also work ! Thanks ! – liubenyuan Jun 26 '13 at 7:49
7

While your use of the \makeatletter...\makeatother pair in creating the definitions is done perfectly, you need to do the same if you reference these definitions elsewhere. So, "scoping" the minipage with another \makeatletter...\makeatother pair solves your problem.

As reference, see What do \makeatletter and \makeatother do?

Some other considerations:

  • Use predefined lengths, rather than absolute ones. Perhaps using \linewidth rather than 736pt would be more appropriate.
  • For back-end macros, using @ in the definitions are fine. However, if you're going to use definitions inside your document content, avoid the use of macros containing @, or build a user interface for that. For example,

    \def\printtitle{\@title}% Display title
    \def\printdisplaytitle{\@displaytitle}% Display title
    \def\printdisplayauthor{\@displayauthor}% Display author
    \def\printdisplayaffiliation{\@displayaffiliation}% Display affiliation
    

    Now you can use

    \textbf{\printdisplayauthor}~~$\cdot$~~%
      \textbf{\printdisplayaffiliation}~\hfill$\cdot$\hfill~%
      \textbf{NUDT} \
    
  • Don't use the old font switches like \bf and \it. See Does it matter if I use \textit or \it, \bfseries or \bf, etc. and Will two-letter font style commands (\bf, \it, …) ever be resurrected in LaTeX?
  • yes! it works like a magic when I put \makeatletter and \makeatother around the minipage. But what if I want to reference the definitions somewhere in the main document, I had to wrapper around, say \@displaytitle, with \makeatletter ... \makeatother, is there any way of working around this extra constrains ? – liubenyuan Jun 26 '13 at 7:36
  • And that fixed width is for the layout of IPE for making representations. Thanks for the suggestions ! – liubenyuan Jun 26 '13 at 7:38
  • @liubenyuan: As mention in my answer, you should avoid that by creating "user interface macros" like \printdisplaytitle. – Werner Jun 26 '13 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.