Difference between revisions of "First Document"

From Wiki
Jump to navigation Jump to search
m
(18 intermediate revisions by 7 users not shown)
Line 1: Line 1:
< [[Main Page]] | [[Second Step]] | [[Next Steps]] >
+
< [[Main Page]] | [[Detailed Example]] >
  
  
What is ConTeXt? What can I do with it? Let’s see. Take your favourite [[text editor]], type in the following document and save it as a file <code>hello.tex</code>.
+
ConTeXt is a ''[http://en.wikipedia.org/wiki/Markup_language markup language]'' used to primarily create PDF files. To use ConTeXt, create a text file (typically with a <code>.tex</code> extension) with ConTeXt markup and ''compile'' the file by running the command <code>context filename</code>. This creates a PDF file. This page explains how to create your very first ConTeXt document.
  
<texcode>
+
== First steps ==
\starttext
 
Hello World
 
\stoptext
 
</texcode>
 
 
 
It shows already a ConTeXt essential: everything's between <tt>\startsomething</tt> and <tt>\stopsomething</tt>.
 
  
If you don't have ConTeXt [[Installation hints|installed]] (yet), you can first try out the latest version using the web interface http://live.contextgarden.net.
+
Make sure that ConTeXt is installed on your system. To check that, go to the command line and type
  
If you already installed it, you can go to the shell/command line and type in
+
<pre>context --version</pre>
  
 +
You should get an output as follows:
 
<pre>
 
<pre>
texexec hello.tex
+
mtx-context    | ConTeXt Process Management 1.03
 +
mtx-context    |
 +
mtx-context    | main context file: /opt/context-minimals/texmf-context/tex/context/base/mkiv/context.mkiv
 +
mtx-context    | current version: 2019.07.24 11:17
 
</pre>
 
</pre>
  
and now ConTeXt will start. It will give you some output on your terminal 
+
If ConTeXt is not installed on your system, check the [[Installation|installation]] page for installation instructions.
 +
 
 +
Follow the steps below to create a simple document using ConTeXt:
 +
 
 +
== Create a ConTeXt file ==
 +
 +
Open a [[Text Editors|text editor]], type the following content, and save the file as <code>hello.tex</code>:
 +
 
 +
<texcode>\starttext
 +
\startsection[title={Testing ConTeXt}]
 +
  This is my {\em first} ConTeXt document.
 +
\stopsection
 +
\stoptext</texcode>
 +
 
 +
Words starting with a backslash (such as <code>\starttext</code>) are called '''command sequence''' or '''macros'''. The macros
 +
 
 +
<texcode>\starttext
 +
....
 +
\stoptext</texcode>
 +
 
 +
mark the content to be typeset. The material before <code>\starttext</code> (called ''preamble'') is used to change the style of the output; any material after <code>\stoptext</code> is ignored.
 +
 
 +
The macros
 +
 
 +
<texcode>\startsection[title={...}]
 +
...
 +
\stopsection</texcode>
 +
 
 +
mark the title and the content of a section.
 +
 
 +
The macro <code>{\em ...}</code> is a [[Font Switching| font switch]] that emphasizes the content (by showing it in slanted font).
 +
 
 +
 
 +
== Compile the ConTeXt file ==
 +
 
 +
Go to the command-line and type:
 +
 
 +
<pre>context hello</pre>
 +
 
 +
ConTeXt will then process your document, display some logging information on the console, and generate a <tt>hello.pdf</tt> output file.
  
 
<pre><nowiki>
 
<pre><nowiki>
TeXExec | processing document 'hello.tex'
+
mtx-context     | run 1: luatex --fmt="/home/adityam/.cache/context-minimals/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luatex/cont-en" --jobname="hello" --lua="/home/adityam/.cache/context-minimals/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luatex/cont-en.lui" --c:currentrun=1 --c:fulljobname="./hello.tex" --c:input="./hello.tex" --c:kindofrun=1 --c:maxnofruns=9 --c:texmfbinpath="/opt/context-minimals/texmf-linux-64/bin" "cont-yes.mkiv"
TeXExec | no ctx file found
 
TeXExec | tex processing method: context
 
TeXExec | TeX run 1
 
TeXExec | writing option file hello.top
 
TeXExec | tex engine: pdfetex
 
TeXExec | tex format: cont-en
 
TeXExec | progname: context
 
This is pdfeTeXk, Version 3.141592-1.30.3-2.2 (Web2c 7.5.5)
 
\write18 enabled.
 
%&-line parsing enabled.
 
(c:\context\usr\local\context\tex\texmf-local/web2c/natural.tcx)
 
entering extended mode
 
(./hello.tex
 
  
ConTeXt  ver: 2006.05.14 23:57 fmt: 2006.5.16 int: english mes: english
+
This is LuaTeX, Version 1.10.1 (TeX Live 2019)
 
+
system commands enabled.
language        : language en is active
+
open source    > level 1, order 1, name '/opt/context-minimals/texmf-context/tex/context/base/mkiv/cont-yes.mkiv'
<protectionstate 0>
+
system          >
 +
system          > ConTeXt  ver: 2019.07.24 11:17 MKIV beta fmt: 2019.8.17 int: english/english
 +
...
 
...
 
...
 +
mkiv lua stats  > lua properties: engine: lua 5.3, used memory: 94 MB, ctx: 93 MB, max: unknown MB), hash chars: min(64,40), symbol mask: utf (τεχ)
 +
mkiv lua stats  > runtime: 0.833 seconds, 1 processed pages, 1 shipped pages, 1.200 pages/second
 +
system          | total runtime: 4.485 seconds
 
</nowiki></pre>
 
</nowiki></pre>
  
Don’t be worried. This is the way it should look. Once texexec has finished, it will leave behind a file called <tt>hello.pdf</tt>. Open it and you will see a "Hello world" on a virtual A4 paper and a page number.
+
== View the generated PDF file ==
 +
 
 +
Open the generated <tt>hello.pdf</tt> PDF file using a [http://en.wikipedia.org/wiki/List_of_PDF_software#Viewers PDF viewer]. It should look as follows:
 +
 
 +
<context mode="mkiv">
 +
% Draw a white frame so that the page is not truncated.
 +
% But it does not seem to work :(
 +
\setupbackgrounds[text][frame=on]
 +
\starttext
 +
\startsection[title={Testing ConTeXt}]
 +
  This is my {\em first} ConTeXt document.
 +
\stopsection
 +
\stoptext
 +
</context>
 +
 
 +
Note that the section has been numbered, the section number and the section title appear in a slightly larger fonts, and the emphasized word comes out in a slanted font.
 +
 
 +
== Modifying the output style ==
 +
 
 +
It is possible to change the style of the output by using appropriate ''setup'' commands in the preamble. For example, to make the section titles bold and to use italic (rather than slanted) font for emphasized words, use
 +
 
 +
<context mode="mkiv" source="yes" text="which gives">
 +
\setuphead[section][style=\bfa]
 +
\setupbodyfontenvironment[default][em=italic]
 +
 
 +
\starttext
 +
\startsection[title={Testing ConTeXt}]
 +
  This is my {\em first} ConTeXt document.
 +
\stopsection
 +
\stoptext
 +
</context>
  
> [[Second Step]]
+
{{Getting started navbox}}

Revision as of 01:56, 25 August 2019

< Main Page | Detailed Example >


ConTeXt is a markup language used to primarily create PDF files. To use ConTeXt, create a text file (typically with a .tex extension) with ConTeXt markup and compile the file by running the command context filename. This creates a PDF file. This page explains how to create your very first ConTeXt document.

First steps

Make sure that ConTeXt is installed on your system. To check that, go to the command line and type

context --version

You should get an output as follows:

mtx-context     | ConTeXt Process Management 1.03
mtx-context     |
mtx-context     | main context file: /opt/context-minimals/texmf-context/tex/context/base/mkiv/context.mkiv
mtx-context     | current version: 2019.07.24 11:17

If ConTeXt is not installed on your system, check the installation page for installation instructions.

Follow the steps below to create a simple document using ConTeXt:

Create a ConTeXt file

Open a text editor, type the following content, and save the file as hello.tex:

\starttext
\startsection[title={Testing ConTeXt}]
  This is my {\em first} ConTeXt document.
\stopsection
\stoptext

Words starting with a backslash (such as \starttext) are called command sequence or macros. The macros

\starttext
....
\stoptext

mark the content to be typeset. The material before \starttext (called preamble) is used to change the style of the output; any material after \stoptext is ignored.

The macros

\startsection[title={...}]
...
\stopsection

mark the title and the content of a section.

The macro {\em ...} is a font switch that emphasizes the content (by showing it in slanted font).


Compile the ConTeXt file

Go to the command-line and type:

context hello

ConTeXt will then process your document, display some logging information on the console, and generate a hello.pdf output file.

mtx-context     | run 1: luatex --fmt="/home/adityam/.cache/context-minimals/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luatex/cont-en" --jobname="hello" --lua="/home/adityam/.cache/context-minimals/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luatex/cont-en.lui" --c:currentrun=1 --c:fulljobname="./hello.tex" --c:input="./hello.tex" --c:kindofrun=1 --c:maxnofruns=9 --c:texmfbinpath="/opt/context-minimals/texmf-linux-64/bin" "cont-yes.mkiv"

This is LuaTeX, Version 1.10.1 (TeX Live 2019) 
 system commands enabled.
open source     > level 1, order 1, name '/opt/context-minimals/texmf-context/tex/context/base/mkiv/cont-yes.mkiv'
system          > 
system          > ConTeXt  ver: 2019.07.24 11:17 MKIV beta  fmt: 2019.8.17  int: english/english
...
...
mkiv lua stats  > lua properties: engine: lua 5.3, used memory: 94 MB, ctx: 93 MB, max: unknown MB), hash chars: min(64,40), symbol mask: utf (τεχ)
mkiv lua stats  > runtime: 0.833 seconds, 1 processed pages, 1 shipped pages, 1.200 pages/second
system          | total runtime: 4.485 seconds

View the generated PDF file

Open the generated hello.pdf PDF file using a PDF viewer. It should look as follows:

Note that the section has been numbered, the section number and the section title appear in a slightly larger fonts, and the emphasized word comes out in a slanted font.

Modifying the output style

It is possible to change the style of the output by using appropriate setup commands in the preamble. For example, to make the section titles bold and to use italic (rather than slanted) font for emphasized words, use

\setuphead[section][style=\bfa]
\setupbodyfontenvironment[default][em=italic]

\starttext
\startsection[title={Testing ConTeXt}]
  This is my {\em first} ConTeXt document.
\stopsection
\stoptext

which gives

Template:Getting started navbox