Difference between revisions of "From LaTeX to ConTeXt"

From Wiki
Jump to navigation Jump to search
(add hint about Pandoc; moved macro from FAQ)
 
(14 intermediate revisions by 5 users not shown)
Line 1: Line 1:
< [[Main Page]] >
+
General hints for converting from LaTeX to Context can be found in
 +
* [http://www.berenddeboer.net/tex/LaTeX2ConTeXt.pdf LaTeX in proper ConTeXt] by [http://www.berenddeboer.net/ Berend de Boer]
 +
A Vietnamese version is available at [http://vnoss.org/docs/LaTeX2ConTeXt-vi.pdf VnOSS].
  
General hints for converting from LaTeX to Context can be found in the [http://www.berenddeboer.net/tex/LaTeX2ConTeXt.pdf LaTeX in proper ConTeXt] manual, by [http://www.berenddeboer.net/ Berend de Boer]
+
This page offers specific advice on a number of special things that you may be doing with LaTeX, but are not so obvious to do with ConTeXt.  
 
 
This page offers specific advice on a number of special things that you may be doing with LaTeX, but are not so obvious to do with ConTeXt.
 
  
 
=== Document and Page Layout ===
 
=== Document and Page Layout ===
 
* [[Document Titles]]: Title blocks, as in the standard LaTeX article.
 
* [[Document Titles]]: Title blocks, as in the standard LaTeX article.
* [[LaTeX Thanks|The thanks command]] adds footnoted information, usually to author blocks.
+
* [[LaTeX Thanks|\thanks{}]] adds footnoted information, usually to author blocks.
 
* [[Article Abstracts]]: Abstracts from the standard LaTeX article or report.
 
* [[Article Abstracts]]: Abstracts from the standard LaTeX article or report.
 
* [[KOMA-scrartcl Type Area]]: An interesting automated type-area setup.
 
* [[KOMA-scrartcl Type Area]]: An interesting automated type-area setup.
Line 13: Line 13:
 
* [[Flush bottom]]
 
* [[Flush bottom]]
 
* [[Vertically Centered Boxes]]: Centering parboxes and tables in a line of text.
 
* [[Vertically Centered Boxes]]: Centering parboxes and tables in a line of text.
+
 
 
=== Text Formatting ===
 
=== Text Formatting ===
 
* [[Bold small caps]]
 
* [[Bold small caps]]
Line 23: Line 23:
 
* So-called (by plain TeX and LaTeX) [[French spacing]]
 
* So-called (by plain TeX and LaTeX) [[French spacing]]
  
=== Command syntax ===
+
=== Idiomatic Differences Between ConTeXt and LaTeX ===
 +
==== Brackets and Braces ====
 +
 
 +
{| border="1" cellspacing="0" cellpadding="2"
 +
|-
 +
|  || {..} || [..]
 +
|-
 +
| LaTeX || command arguments  || optional arguments
 +
|-
 +
| ConTeXt || typeset material; scope or range of the command (the text acted upon) is placed between curly brackets || setups instructions and metadata (options)
 +
|-
 +
|}
  
''Looks similar, but...''
+
==== Optional Arguments and Setups ====
 +
In ConTeXt, arguments may be either
 +
[[System Macros/Comma Separated Lists|comma separated lists]]
 +
or [[System Macros/Key_Value_Assignments|assignments]], but
 +
<em>not</em> both. The following example demonstrates that LaTeX
 +
allows either syntax in optional arguments:
 +
<pre>
 +
\documentclass[BCOR=12mm,DIV=calc,twoside]{scrartcl}
 +
</pre>
 +
(From the [http://mirrors.ctan.org/macros/latex/contrib/koma-script/scrguien.pdf KOMA-Script manual].)
 +
ConTeXt, however, distinguishes strictly between both types for
 +
processing them internally relies on two different
 +
mechanisms. Therefore, setups like {{cmd|itemize}} usually
 +
allow two sets of optional arguments
 +
[http://article.gmane.org/gmane.comp.tex.context/75276], the
 +
comma list preceding the assignment:
  
'''LaTeX''':
+
<texcode>
"Command arguments are enclosed in curly braces { and },
+
\starttext
except for optional arguments, which are enclosed in square
 
brackets [ and ]."
 
  
'''ConTeXt''':
+
\startitemize [R,2*broad][
"A command is often followed by setups or by text. Setups
+
  start=11,
are placed between brackets ([]). The scope or range of
+
  before=\startlinecorrection,
the command, the text acted upon, is placed between
+
  after=\stoplinecorrection,
curly brackets ({})."
+
]
 +
  \item Foo,
 +
  \item bar,
 +
  \item baz.
 +
\stopitemize
  
In other words,
+
\stoptext
 +
</texcode>
  
* arguments in {} pairs are typeset material
+
The ConTeXt interface definitions
* arguments in [] are setup instructions and metadata
+
(collected by Wolfgang in the [https://bitbucket.org/wolfs/commands/overview macro reference])
 +
use a special notation to indicate whether an argument
 +
expects assignment or list syntax:
 +
<pre>
 +
\defineframedtext [...] [...] [..,.=.,..]
 +
</pre>
 +
where <code>[...]</code> stands for the <em>list</em> type and
 +
<code>[..,.=.,..]</code> denotates an <em>assignment</em>.
  
 
=== Programming ===
 
=== Programming ===
Line 54: Line 90:
 
* [[LaTeX Math in ConTeXt]]
 
* [[LaTeX Math in ConTeXt]]
  
 +
=== Automatical converting ===
 +
 +
[https://pandoc.org Pandoc] can read LaTeX and write ConTeXt (but not the other way round).
  
 
=== Copy-Paste text between LaTeX and ConTeXt ===
 
=== Copy-Paste text between LaTeX and ConTeXt ===
  
It is sometimes useful to have the same source for a latex document and context presentation (or context document and latex presentation). However, the commands used by both are very different. Can someone describe some definations in context that implement the core functionality of latex commands like \section et al, \textbf et al, \bfseries et al and \begin \end pairs?
+
It is sometimes useful to have the same source for a LaTeX document and a ConTeXt presentation (or a ConTeXt document and a LaTeX presentation). However, the commands used by both are very different. Can someone describe some definitions in ConTeXt that implement the core functionality of LaTeX commands like \section et al, \textbf et al, \bfseries et al and \begin \end pairs?
{{Howto}}
 
  
 
''<code>\section</code> works the same way as in LaTeX, for mathematics take a look into [[LaTeX Math in ConTeXt]], use <code>\bf</code> instead of <code>\textbf</code> for both LaTeX and ConTeXt (or <code><nowiki>\def\textbf#1{{\bf #1}}</nowiki></code>) and as a general rule: use as many plain TeX macros as possible instead of LaTeX-specific macros. <code>\begin ... \end</code> only works for math as far as I know. See also other documents listed above  or ask on the mailing list.''
 
''<code>\section</code> works the same way as in LaTeX, for mathematics take a look into [[LaTeX Math in ConTeXt]], use <code>\bf</code> instead of <code>\textbf</code> for both LaTeX and ConTeXt (or <code><nowiki>\def\textbf#1{{\bf #1}}</nowiki></code>) and as a general rule: use as many plain TeX macros as possible instead of LaTeX-specific macros. <code>\begin ... \end</code> only works for math as far as I know. See also other documents listed above  or ask on the mailing list.''
 
 
<!--
 
<!--
 
* [[LaTeX&ConTeXt/Introduction|Introduction]]
 
* [[LaTeX&ConTeXt/Introduction|Introduction]]
Line 69: Line 106:
 
-->
 
-->
  
 +
== Functionality of Latex Packages in Context ==
 +
 +
* [[Latex Packages]]
 +
 +
=== How transcribe this LaTeX macro to ConTeXt? ===
 +
 +
(This was moved from the [[FAQ]] where it didn’t make sense.)
 +
 +
How to transcribe this macro controlling that no last line of a paragraph is shorter than the paragraph indenting?
 +
 +
<texcode>
 +
\parfillskip=\hsize
 +
\advance\parfillskip by -1.5\parindent
 +
\advance\parfillskip by 0pt minus \parfillskip
 +
\advance\parfillskip by 0pt minus -1em
 +
</texcode>
 +
 +
Like this:
 +
<texcode>
 +
\installalign
 +
  {block}
 +
  {\parfillskip=\hsize
 +
  \advance\parfillskip by -1.5\parindent
 +
  \advance\parfillskip by 0pt minus \parfillskip
 +
  \advance\parfillskip by 0pt minus -1em}
 +
 +
% followed by
 +
\setupalign[block]
 +
</texcode>
  
A Vietnamese version of <i>LaTeX in proper ConTeXt</i> is available at [http://vnoss.org/docs/LaTeX2ConTeXt-vi.pdf VnOSS].
 
  
== Functionality of Latex Packages in Context ==
+
[[Category:From LaTeX]]
* [[Latex Packages]]
 

Latest revision as of 17:53, 24 April 2024

General hints for converting from LaTeX to Context can be found in

A Vietnamese version is available at VnOSS.

This page offers specific advice on a number of special things that you may be doing with LaTeX, but are not so obvious to do with ConTeXt.

Document and Page Layout

Text Formatting

Idiomatic Differences Between ConTeXt and LaTeX

Brackets and Braces

{..} [..]
LaTeX command arguments optional arguments
ConTeXt typeset material; scope or range of the command (the text acted upon) is placed between curly brackets setups instructions and metadata (options)

Optional Arguments and Setups

In ConTeXt, arguments may be either comma separated lists or assignments, but not both. The following example demonstrates that LaTeX allows either syntax in optional arguments:

 \documentclass[BCOR=12mm,DIV=calc,twoside]{scrartcl}

(From the KOMA-Script manual.) ConTeXt, however, distinguishes strictly between both types for processing them internally relies on two different mechanisms. Therefore, setups like \itemize usually allow two sets of optional arguments [1], the comma list preceding the assignment:

\starttext

\startitemize [R,2*broad][
  start=11,
  before=\startlinecorrection,
  after=\stoplinecorrection,
]
  \item Foo,
  \item bar,
  \item baz.
\stopitemize

\stoptext

The ConTeXt interface definitions (collected by Wolfgang in the macro reference) use a special notation to indicate whether an argument expects assignment or list syntax:

\defineframedtext [...] [...] [..,.=.,..]

where [...] stands for the list type and [..,.=.,..] denotates an assignment.

Programming

Document Metadata

Math

Automatical converting

Pandoc can read LaTeX and write ConTeXt (but not the other way round).

Copy-Paste text between LaTeX and ConTeXt

It is sometimes useful to have the same source for a LaTeX document and a ConTeXt presentation (or a ConTeXt document and a LaTeX presentation). However, the commands used by both are very different. Can someone describe some definitions in ConTeXt that implement the core functionality of LaTeX commands like \section et al, \textbf et al, \bfseries et al and \begin \end pairs?

\section works the same way as in LaTeX, for mathematics take a look into LaTeX Math in ConTeXt, use \bf instead of \textbf for both LaTeX and ConTeXt (or \def\textbf#1{{\bf #1}}) and as a general rule: use as many plain TeX macros as possible instead of LaTeX-specific macros. \begin ... \end only works for math as far as I know. See also other documents listed above or ask on the mailing list.

Functionality of Latex Packages in Context

How transcribe this LaTeX macro to ConTeXt?

(This was moved from the FAQ where it didn’t make sense.)

How to transcribe this macro controlling that no last line of a paragraph is shorter than the paragraph indenting?

\parfillskip=\hsize
\advance\parfillskip by -1.5\parindent
\advance\parfillskip by 0pt minus \parfillskip
\advance\parfillskip by 0pt minus -1em

Like this:

\installalign
  {block}
  {\parfillskip=\hsize
   \advance\parfillskip by -1.5\parindent
   \advance\parfillskip by 0pt minus \parfillskip
   \advance\parfillskip by 0pt minus -1em}

% followed by
\setupalign[block]