1

I have a class resume which I use in a .tex file as

\documentclass{resume}

\begin{document}
\end{document}

but I also want to define some variables in my .tex document to be used in my class.

How can I, for instance, use the variables/properties that I set in

\documentclass{resume}

\name{John Doe}
\address{Street 10}
\phone{No phone}

\begin{document}
\end{document}

in my class?

5
  • Did you write resume.cls? Or is this some other class that already provides \name, \address and \phone?
    – Werner
    Commented Dec 10, 2015 at 7:14
  • I write resume.cls myself, so I guess I have to define some placeholders in my class and overwrite them with \name{...} in my .tex file.
    – Jamgreen
    Commented Dec 10, 2015 at 7:22
  • 1
    Oh please, not another resume class. There are already a bunch of them out there.
    – Johannes_B
    Commented Dec 19, 2015 at 14:12
  • I am confused. Normally you create commands in the .cls that you can access/use in your .tex file. But you seem to be asking to create commands in your .tex file that will be accessed/used in the .cls, which does not make sense (or, probably, I can't see the sense of what this is supposed to accomplish).
    – jon
    Commented May 20, 2016 at 2:15
  • How can we help if this uses a custom class we don't have access to? Confused.
    – cfr
    Commented May 20, 2016 at 2:44

2 Answers 2

2

Well, only defining commands \name etc. is only the first step. You need to define where should it be printed, for example inside \maketitle, how to layout the cv, font, fontsize etc.

That is at all not so easy as it seems you think.

With \newcommand{\name}{Firstname lastname} you can define a command \name printing "Firstname Lastname" where it is used. With \renewcommand{\name}{John Doe} you can change the placeholder to an (perhaps) real name.

If you are realy interested in learning writing own classes please read and study first clsguide.pdf. You can read it with typing texdoc clsguide into your console/terminal. Then there are some questions here about classes, for example Pass parameter to class or creating a class or package etc.

Be prepared it would take a little bit time (or more) to learn what you have to do. Look into other classes what they do.

Or look for example on CTAN for existing classes to create an CV, for example moderncv.

0

In the .tex file, declare a variable:

\foo{BAR}

And in the .cls file, use this expression:

\newcommand{\foo}[1]{\renewcommand{\foo}{#1}}

Apparently, .tex and .cls files have separate namespaces and are compiled separately, even though you "import" the class at the top of your .tex file.

Adding the \renewcommand expression in the .cls file makes sure that \foo is recognized as a command by other functions in it. Effectively, you overwrite the initial definition of \foo as a command that takes in one argument (\newcommand{\foo}[1]) with its value presented in .tex

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .