Difference between revisions of "Document Titles"

From Wiki
Jump to navigation Jump to search
m (Another minor wording change.)
m (Fixed the programming bug, added crosslink to Article Abstracts.)
Line 57: Line 57:
 
== In ConTeXt: A more reusable solution ==
 
== In ConTeXt: A more reusable solution ==
  
The simple solution replicates the appearance of the LaTeX original, but it doesn't replicate the spirit of it, which is to separate the formatting from the content.  We can do this by creating the following definitions, and putting them in a module file.  The <code>\title</code> and similar commands are copied nearly directly from the LaTeX kernel, and the formatting command the same as the previous version.
+
The simple solution replicates the appearance of the LaTeX original, but it doesn't replicate the spirit of it, which is to separate the formatting from the content.  We can do this by creating the following definitions, and putting them in a module file.  The <code>\title</code> and similar commands are copied nearly directly from the LaTeX kernel, and the formatting command the same as the previous version -- note that we use <code>\doctitle</code> instead of <code>\title</code>, to avoid obliterating the <code>\title</code> command that ConTeXt is already using for unnumbered sections.
  
 
<texcode>
 
<texcode>
 
\unprotect
 
\unprotect
\def\title#1{\gdef\@title{#1}}
+
\def\doctitle#1{\gdef\@title{#1}}
 
\def\author#1{\gdef\@author{#1}}
 
\def\author#1{\gdef\@author{#1}}
 
\def\date#1{\gdef\@date{#1}}
 
\def\date#1{\gdef\@date{#1}}
Line 83: Line 83:
 
<texcode>
 
<texcode>
 
\usepackage[title]
 
\usepackage[title]
   \title{How to do this in Context}
+
   \doctitle{How to do this in Context}
 
   \author{The author}
 
   \author{The author}
 
   \date{July 26, 2005}
 
   \date{July 26, 2005}
Line 98: Line 98:
 
<context>
 
<context>
 
\unprotect
 
\unprotect
\def\title#1{\gdef\@title{#1}}
+
\def\doctitle#1{\gdef\@title{#1}}
 
\def\author#1{\gdef\@author{#1}}
 
\def\author#1{\gdef\@author{#1}}
 
\def\date#1{\gdef\@date{#1}}
 
\def\date#1{\gdef\@date{#1}}
Line 115: Line 115:
 
\protect
 
\protect
  
\title{How to do this in Context}
+
\doctitle{How to do this in Context}
 
\author{The author}
 
\author{The author}
 
\date{July 26, 2005}
 
\date{July 26, 2005}
Line 125: Line 125:
 
\stoptext
 
\stoptext
 
</context>
 
</context>
 +
 +
 +
So, that's the title.  The abstract can be handled very similarly; see [[Article Abstracts]] for details.

Revision as of 01:46, 4 September 2005

< From LaTeX to ConTeXt >

In LaTeX

The standard LaTeX document classes define a \maketitle command, along with \title, \author, and \date commands, which can be used to produce a relatively automatic title block.

\documentclass{article}
  \title{How to do this in Context}
  \author{The author}
  \date{July 26, 2005}
\begin{document}
  \maketitle
\end{document}

The title, author, and date defined by these commands is also used to create the PDF authoring information, if appropriate packages are used. (I'm not sure of the details of this; will look them up later. --Brooks)

In ConTeXt: A simple solution

The ConTeXt philosophy is for the author to specify the formatting, rather than selecting from existing formats. A simple solution is thus to write the title block directly; the following version is a close approximation of the version produced by the \maketitle command in LaTeX's startard article class. Obviously, the fine details of spacing and font sizes and so forth can be adjusted as desired.

\starttext
\startalignment[center]
  \blank[2*big]
    {\tfd How to do this in Context}
  \blank[3*medium]
    {\tfa The author}
  \blank[2*medium]
    {\tfa July 26, 2005}
  \blank[3*medium]
\stopalignment

Then, the actual text of the document starts here.  We'll put in enough text to
fill out the line and start to make a paragraph.
\stoptext

In ConTeXt: A more reusable solution

The simple solution replicates the appearance of the LaTeX original, but it doesn't replicate the spirit of it, which is to separate the formatting from the content. We can do this by creating the following definitions, and putting them in a module file. The \title and similar commands are copied nearly directly from the LaTeX kernel, and the formatting command the same as the previous version -- note that we use \doctitle instead of \title, to avoid obliterating the \title command that ConTeXt is already using for unnumbered sections.

\unprotect
\def\doctitle#1{\gdef\@title{#1}}
\def\author#1{\gdef\@author{#1}}
\def\date#1{\gdef\@date{#1}}
\date{\today}  % Default to today unless specified otherwise.

\def\maketitle{%
  \startalignment[center]
    \blank[2*big]
      {\tfd \@title}
    \blank[3*medium]
      {\tfa \@author}
    \blank[2*medium]
      {\tfa \@date}
    \blank[3*medium]
  \stopalignment}
\protect

Suppose that we save this in the file t-title.tex. 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 \usepackage[title] command in place of \documentclass{article}.

\usepackage[title]
  \doctitle{How to do this in Context}
  \author{The author}
  \date{July 26, 2005}

\starttext
  \maketitle
  Then, the actual text of the document starts here.  We'll put in enough text to
  fill out the line and start to make a paragraph.
\stoptext

The result is, of course, identical to the previous version. Now, the t-title.tex macros can be shared between any number of documents, and changes will affect all of the documents that use this file.


So, that's the title. The abstract can be handled very similarly; see Article Abstracts for details.