Changes

Jump to navigation Jump to search
2,676 bytes added ,  13:20, 9 August 2020
m
Text replacement - "<cmd>" to "{{cmd|"
</texcode>
The title, author, and date defined by these commands is also used to create the PDF authoring information, if appropriate packages , like hyperref, are used. (I'm not sure of the details of this; will look them up laterHyperref can set these fields using \pdfauthor{\theauthor} etc. --Brooks)
== In ConTeXt: A simple solution ==
\starttext
\startalignment[center]
\blank[force,2*big]
{\tfd How to do this in Context}
\blank[3*medium]
\def\author#1{\gdef\@author{#1}}
\def\date#1{\gdef\@date{#1}}
\date{\todaycurrentdate} % Default to today unless specified otherwise.
\def\maketitle{%
\startalignment[center]
\blank[force,2*big]
{\tfd \@title}
\blank[3*medium]
</texcode>
Suppose that we save this in the file <code>t-title.tex</code>. Then, we can use this in our main ConTeXt document with the following syntax, which is quite similar to the LaTeX version aside from the addition of the <{{cmd>|usemodule</cmd>}}<tt>[title]</tt> command in place of <code>\documentclass{article}</code>.
<texcode>
and changes will affect all of the documents that use this file.
== In ConTeXt: A more advanced solution == The next solution use an interface inspired by the ones from the core commands and tries to go away from hard coded values. The values for the title are set with the <code>\setuptitle</code> command, it provides two arguments where the second argument is optional and could be used to change the layout for the three text blocks. The title block itself is placed with the <code>\placetitle</code> command. <texcode>\unprotect \definesystemvariable {dt} % DocumentTitle % Expand both 1- and 2- arity'd versions of /dosetuptitle\def\setuptitle {\dodoubleempty\dosetuptitle} % The one-argument iteration:% For each comma separated item of arg1, define (dtcontent(arg1))...% using \setuptitle in your document as defined at the bottom of this file % The two-argument iteration:% For each comma separated item of arg1, and using style/color in arg2...% define (dt(arg1)(style)) and (dt(arg1)(color)) \def\dosetuptitle[#1][#2]% {\ifsecondargument \dodosetuptitle[#1][#2]% \else \dodosetuptitle[\v!content][#1]% \fi} \def\dodosetuptitle[#1][#2]% {\def\dododosetuptitle##1% {\getparameters[\??dt##1][#2]}% \processcommalist[#1]\dododosetuptitle} % Using earlier style/color definitions, apply style and color to arg1-item values\def\placetitle {\startalignment[\v!middle] \blank[\v!force,2*\v!big] \doattributes{\??dt\c!title}\c!style\c!color\@@dtcontenttitle \blank[3*\v!medium] \doattributes{\??dt\c!author}\c!style\c!color\@@dtcontentauthor \blank[2*\v!medium] \doattributes{\??dt\c!date}\c!style\c!color\@@dtcontentdate \blank[3*\v!medium] \stopalignment}  % Here is where we define the key-value pairs\setuptitle [\c!title] [\c!style=\tfd, \c!color=] \setuptitle [\c!author,\c!date] [\c!style=\tfa, \c!color=] \setuptitle [\c!title=, \c!author=, \c!date=\currentdate] \protect</texcode> To reuse the definition above you could save the code in module like <code>t-title.tex</code> and load it in your document with <code>\usemodule[title]</code>. <texcode>\setuptitle [title={How to do this in Context}, author={The author}, date={July 26, 2005}] \starttext \placetitle Then, the actual text of the document starts here. We'll put in enough text tofill out the line and start to make a paragraph. \stoptext</texcode> The definition for the macro <code>\placetitle</code> could be extended without problems to change the values for the space before and after the title block or the distance between all elements with the <code>\setuptitle</code> command. == Adding markings to headers and footers (in "A more reusable solution") ==
With just a few extra lines and two redefined definitions in this module,
\def\author#1{\gdef\@author{#1}\marking[Author]{#1}}
\def\date#1{\gdef\@date{#1}}
\date{\todaycurrentdate} % Default to today unless specified otherwise.
\def\maketitle{%

Navigation menu