Generallittle problem with \def

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
krauzo
Posts: 3
Joined: Thu Sep 25, 2008 4:15 pm

little problem with \def

Post by krauzo »

Hi, I'm beginner in LaTeX

I have a little problem.. I want to divide code of the document into two pieces: a style, where i could keep all of the visual attributes of the document and a file for the variables, which would generate a whole document using the provided variables.

After all the problem i have is related with the \def command. I think I'm using it wrong.

Here's what i've got:
VARIABLES FILE:

Code: Select all

\documentclass[a4paper,10pt,twoside,notitlepage,onecolumn]{cert}

\begin{document}

\pagestyle{fancy}
\fancyhead[CE,CO]{\ }
\fancyfoot[CE,CO]{\ }

\ \\ \ \\ \ \\ \ \\
\cert{John Smith|Programming|JAVA, SQL, C++|Andrew Norton|New York}
\end{document}

STYLE FILE:
usepackage's etc AND:

Code: Select all

\def\title #1{%
\begin{center}
\Huge
\textbf{
#1}
\end{center}
\normalfont
\normalsize}

\def\name #1{%
\begin{center}
\huge
\normalfont
#1
\end{center}
\normalsize}

\def\normal #1{%
\begin{center}
\Large
\normalfont
#1
\end{center}}

\def\person #1{%
\begin{center}
\Huge
\normalfont
#1
\end{center}
\normalsize}

\def\leader #1{%
\begin{flushright}
\large
\normalfont
#1
\end{flushright}
\normalsize}

\def\dateandplace #1{%
\begin{flushleft}
\large
\normalfont
#1
\end{flushleft}
\normalsize}

\def\cert {#1|#2|#3|#4|#5}{%
\title{CERTIFICATE}%
\name{Of finished course:\#1}%
\normal{For}\person{\#2}%
\normal{Contents of the course \#3}%
\leader{author: \#4}%
\dateandplace{\#5}}%
AND THIS IS THE ERROR I GET:
I get a lot of "You can't use `macro parameter character #' in horizontal mode \cert->##1##2##3##4##5 1.20 \cert

Also the document does not work properly: in places, where there should be my variables there is only text like #1 or #2 etc

I've searched for this kind of error for a long time and I didn't find any clues that may help.. I would appreciate any kind of help, thx in advance

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

little problem with \def

Post by Stefan Kottwitz »

Hi,

it looks a bit strange to me.
Concerning cert it could be modified to:

Code: Select all

\def\cert#1|#2|#3|#4|#5{%
\title{CERTIFICATE}%
\name{Of finished course:#1}%
\normal{For}\person{#2}%
\normal{Contents of the course #3}%
\leader{author: #4}%
\dateandplace{#5}}
i.e. less braces in the first line and no backslash before the parameters. Nevertheless I think this definition is not really comfortable with those |.

Stefan
LaTeX.org admin
krauzo
Posts: 3
Joined: Thu Sep 25, 2008 4:15 pm

little problem with \def

Post by krauzo »

thx for help, but after the changes above i get:
Runaway argument?

{John Smith|Programming|JAVA, SQL, C++|Andrew Norton|New York}
\end{document}

! File enden while scanning use of \cert
<inserted text>
\par
<*> certificate.tex
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

little problem with \def

Post by Stefan Kottwitz »

This call should work:

Code: Select all

\cert{John Smith}|{Programming}|{JAVA, SQL, C++}|{Andrew Norton}|{New York}
I wouldn't use those | in a definition.

Stefan
LaTeX.org admin
krauzo
Posts: 3
Joined: Thu Sep 25, 2008 4:15 pm

Re: little problem with \def

Post by krauzo »

now it works :)

Thanks a lot :) you really helped me
Post Reply