TransWikia.com

Custom commands like title and authors

TeX - LaTeX Asked by Jake B. on August 7, 2020

When I use

title{My title}
quthor{Myself}

I can later access these two parameters in the class file by using

@title and @quthor

Is there a way to define my own custom fields, like

cost{This book costs loads}
subtitle{My subtitle}
reviewer{This person revewed the book}

How do I do it?

2 Answers

Yes, you can by using newcommand{tag}{reference} option to define such custom fields as in:

newcommand{cost}{This book costs loads}
newcommand{subtitle}{My subtitle}
newcommand{reviewer}{This person reviewed the book}

For instance, when you use cost, it will replace and print "This book costs loads" on your document. I hope that help.

Answered by Burak Karaosmanoğlu on August 7, 2020

It's not difficult, just look up the definition of title.

cmd input

latexdef -s title

return

% latex.ltx, line 7370:
DeclareRobustCommandtitle[1]{gdef@title{#1}}

So we can write code like this

documentclass{article}
makeatletter
DeclareRobustCommandmycmd[1]{gdef@mycmd{#1}}
newcommand{test}{These are my orders! @mycmd}
makeatother

mycmd{123}

begin{document}
  test
end{document}

Answered by sikouhjw on August 7, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP