Difference between revisions of "First Document"

From Wiki
Jump to navigation Jump to search
m (There is really no need to mention MkII to a beginner)
m
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
< [[Main Page]] | [[Second Step]] | [[Next Steps]] >
+
< [[Main Page]] | [[Detailed Example]] >
  
This page describes the fundamentals of using ConTeXt. It includes hands-on examples, and the instructions assume that you have ConTeXt [[Installation hints|installed]]. If you don't want to install it yet, you can [http://live.contextgarden.net try it on the web].
 
  
Start by typing the following into a [[Text Editors|text editor]] and saving it as <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
+
Make sure that ConTeXt is installed on your system. To check that, go to the command line and type
\stoptext
 
</texcode>
 
  
Then go to the command-line and type:
+
<pre>context --version</pre>
  
 +
You should get an output as follows:
 
<pre>
 
<pre>
context hello.tex
+
mtx-context     | ConTeXt Process Management 0.61
 +
mtx-context    |
 +
mtx-context    | main context file: /opt/context-minimals/texmf-context/tex/context/base/context.mkiv
 +
mtx-context    | current version: 2014.12.29 10:01
 
</pre>
 
</pre>
  
ConTeXt will then process your document. It will output some information, such as follows—this output does ''not'' indicate an error:
+
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>
Line 26: Line 66:
  
 
ConTeXt  ver: 2013.01.27 21:24 MKIV  fmt: 2013.1.28  int: english/english
 
ConTeXt  ver: 2013.01.27 21:24 MKIV  fmt: 2013.1.28  int: english/english
 
+
...
system          > cont-new.mkiv loaded
+
...
(/opt/context-minimals/texmf-context/tex/context/base/cont-new.mkiv
 
system          > beware: some patches loaded from cont-new.mkiv
 
)
 
system          > files > jobname: hello, input: hello, result: hello
 
fonts          > latin modern fonts are not preloaded
 
languages      > language en is active
 
(hello.tex{/opt/context-minimals/texmf-fonts/fonts/map/pdftex/context/mkiv-base.map}
 
fonts          > preloading latin modern fonts (second stage)
 
fonts          > typescripts > unknown: library 'loc'
 
{/opt/context-minimals/texmf-fonts/fonts/map/dvips/lm/lm-math.map}{/opt/context-minimals/texmf-fonts/fonts/map/dvips/lm/lm-rm.map}
 
fonts          > fallback modern rm 12pt is loaded
 
backend        > xmp > using file '/opt/context-minimals/texmf-context/tex/context/base/lpdf-pdx.xml'
 
pages          > flushing realpage 1, userpage 1
 
) )</opt/context-minimals/texmf-fonts/fonts/opentype/public/lm/lmroman12-regular.otf>
 
mkiv lua stats  > used config file          - selfautoparent:/texmf/web2c/texmfcnf.lua
 
mkiv lua stats  > used cache path          - /home/adityam/texmf-cache/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e
 
mkiv lua stats  > resource resolver        - loadtime 0.098 seconds, 1 scans with scantime 0.083 seconds, 21 shared scans, 13 found files, scanned paths: /home/adityam/texmf
 
mkiv lua stats  > stored bytecode data      - 318 modules (0.150 sec), 68 tables (0.000 sec), 386 chunks (0.150 sec)
 
mkiv lua stats  > cleaned up reserved nodes - 41 nodes, 9 lists of 441
 
mkiv lua stats  > node memory usage        - 2 glue, 2 penalty, 9 attribute, 28 glue_spec, 3 attribute_list
 
mkiv lua stats  > node list callback tasks  - 6 unique task lists, 5 instances (re)created, 39 calls
 
mkiv lua stats  > used backend              - pdf (backend for directly generating pdf output)
 
mkiv lua stats  > loaded patterns          - en::2
 
mkiv lua stats  > jobdata time              - 0.001 seconds saving, 0.000 seconds loading
 
mkiv lua stats  > callbacks                - 135 direct, 178 indirect, 313 total
 
mkiv lua stats  > randomizer                - resumed with value 0.13015339995276
 
mkiv lua stats  > lxml preparation time    - 0.000 seconds, 0 nodes, 15 lpath calls, 0 cached calls
 
mkiv lua stats  > result saved in file      - hello.pdf, compresslevel 3, objectcompreslevel 3
 
mkiv lua stats  > loaded fonts              - 2 files: lmroman12-regular.otf latinmodernmath-regular.otf
 
mkiv lua stats  > fonts load time          - 0.069 seconds
 
mkiv lua stats  > luatex banner            - this is luatex, version beta-0.74.0-2012122511  (tex live 2013/dev)(rev 4541)
 
mkiv lua stats  > control sequences        - 36422 of 65536 + 100000
 
 
mkiv lua stats  > current memory usage      - 23 MB (ctx: 23 MB)
 
mkiv lua stats  > current memory usage      - 23 MB (ctx: 23 MB)
 
mkiv lua stats  > runtime                  - 0.316 seconds, 1 processed pages, 1 shipped pages, 3.165 pages/second
 
mkiv lua stats  > runtime                  - 0.316 seconds, 1 processed pages, 1 shipped pages, 3.165 pages/second
Line 66: Line 74:
 
</nowiki></pre>
 
</nowiki></pre>
  
Once <tt>context</tt> has finished, it will leave behind a file called <tt>hello.pdf</tt>. Open it and you will see a "Hello world" document.
+
== View the generated PDF file ==
  
<context source="no" mode="mkiv">
+
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
 
\starttext
Hello World
+
\startsection[title={Testing ConTeXt}]
 +
  This is my {\em first} ConTeXt document.
 +
\stopsection
 
\stoptext
 
\stoptext
 
</context>
 
</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.
  
&rarr; [[Second Step]]
+
== 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>
  
 
{{Getting started navbox}}
 
{{Getting started navbox}}

Revision as of 04:26, 22 May 2015

< 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 0.61
mtx-context     |
mtx-context     | main context file: /opt/context-minimals/texmf-context/tex/context/base/context.mkiv
mtx-context     | current version: 2014.12.29 10:01

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="/opt/context-minimals/texmf-cache/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luatex/cont-en" --jobname="hello" --lua="/opt/context-minimals/texmf-cache/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e/formats/luatex/cont-en.lui" --no-parse-first-line --c:currentrun=1 --c:fulljobname="./hello.tex" --c:input="./hello.tex" --c:kindofrun=1 "cont-yes.mkiv"
This is LuaTeX, Version beta-0.74.0-2012122511 (rev 4541) 
 \write18 enabled.
(/opt/context-minimals/texmf-context/tex/context/base/cont-yes.mkiv

ConTeXt  ver: 2013.01.27 21:24 MKIV  fmt: 2013.1.28  int: english/english
...
...
mkiv lua stats  > current memory usage      - 23 MB (ctx: 23 MB)
mkiv lua stats  > runtime                   - 0.316 seconds, 1 processed pages, 1 shipped pages, 3.165 pages/second

system          | total runtime: 0.468

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