每次出现有关解析 tex 语法的问题时,第一个答案都是:这是不可能的,这里有一个(复杂的)例子来解释原因。
因此,我试图将问题的范围缩小到所谓的经典语法:
\command[optional]{mandatory}{mandatory}
或者就 ConTeXt 的情况来说:
\command[non-print][key=value]{arguemnt}...
答案1
如果目标是生成 HTML 文件,那么 ConTeXt 导出机制是最佳选择。这是一个测试文件:
\setupbackend[export=yes]
\starttext
\startsection[title={Test of export}]
This is to test how \CONTEXT\ export works. First, we input a test file
below.
\startnarrower
\input ward
\stopnarrower
Let's see some other environments, such as\footnote{Note that we define a
float in \in{Figure}[fig:mill].}
\startitemize[n]
\item A table:
\startTABLE
\NC 1 \NC 2 \NC 3 \NC \NR
\NC 1 \NC 2 \NC 3 \NC \NR
\NC 1 \NC 2 \NC 3 \NC \NR
\stopTABLE
\item A formula
\startformula
α^2 + β^2 = 2
\stopformula
\item A figure
\externalfigure[mill.png][width=5cm]
\stopitemize
\startplacefigure
[title={This is a Mill}, reference={fig:mill}]
\externalfigure[mill.png][width=5cm]
\stopplacefigure
\stopsection
\stoptext
当您使用 编译它时,您将获得一个包含以下内容的context filename
目录:filename-export
images
目录styles
目录(包含与不同环境设置相对应的 css 文件)filename-div.xhtml
(每个环境都导出为<div class=...>
)filename-tag.xhtml
(每个环境都导出为<environment>
)filename-raw.xml
(一个xml文档,类似于tag-test.xhtml)filename-pub.lua
(帮助生成 ePub 文件的辅助程序)。
例如对于上述文件,该filename-div.xhtml
文件为:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!--
input filename : test
processing date : Wed Sep 16 12:28:10 2015
context version : 2015.09.13 13:31
exporter version : 0.34
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:math="http://www.w3.org/1998/Math/MathML">
<head>
<meta charset="utf-8"/>
<title>no title</title>
<link type="text/css" rel="stylesheet" href="styles/test-defaults.css" />
<link type="text/css" rel="stylesheet" href="styles/test-images.css" />
<link type="text/css" rel="stylesheet" href="styles/test-styles.css" />
</head>
<body>
<div xmlns="http://www.pragma-ade.com/context/export">
<div class="warning">Rendering can be suboptimal because there is no default/fallback css loaded.</div>
<div>
<div class="metadata">
</div>
<div id="aut-1" class="section level-3">
<div class="sectionnumber">1</div>
<div class="sectiontitle">Test of export</div>
<div class="sectioncontent">
This is to test how ConTEXt export works. First, we input a test file below.
<div class="break"><!--empty--></div>
The Earth, as a habitat for animal life, is in old age and has a fatal illness. Several, in fact. It would be happening whether humans had ever evolved or not. But our presence is like the effect of an old-age patient who smokes many packs of cigarettes per day <div class="subsentencesymbol symbol-middle">—</div> and we humans are the cigarettes.
<div class="break"><!--empty--></div>
Let’s see some other environments, such as<div class="descriptionsymbol footnote insert-1"><div class="sup">1</div></div>
<div class="itemgroup itemize level-1 symbol-n">
<div class="item">
<div class="itemtag">1.</div>
<div class="itemcontent">A table:<div class="table"><div class="tablerow"><div class="tablecell align-flushleft"> 1 </div><div class="tablecell align-flushleft"> 2 </div><div class="tablecell align-flushleft"> 3 </div></div><div class="tablerow"><div class="tablecell align-flushleft"> 1 </div><div class="tablecell align-flushleft"> 2 </div><div class="tablecell align-flushleft"> 3 </div></div><div class="tablerow"><div class="tablecell align-flushleft"> 1 </div><div class="tablecell align-flushleft"> 2 </div><div class="tablecell align-flushleft"> 3 </div></div></div></div>
</div>
<div class="item">
<div class="itemtag">2.</div>
<div class="itemcontent">A formula<div class="formula"> <div class="formulacontent"><m:math display="block" xmlns:m="http://www.w3.org/1998/Math/MathML"><m:mrow><m:msup><m:mi>