% \iffalse meta-comment
% A LaTeX Class and Package for OMDoc Text Fragments
% Copyright (c) 2010 Michael Kohlhase, all rights reserved
%               this file is released under the
%               LaTeX Project Public License (LPPL)
%
% The original of this file is in the public repository at 
% http://github.com/KWARC/sTeX/
% \fi
%   
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{omtext}[2019/03/20 v1.1 OMDoc Text Fragments]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[utf8]{inputenc}
\usepackage{url,array,float,amsfonts}
\usepackage{omtext,omdoc}
\usepackage{graphicx}
\usepackage[show]{ed}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\addbibresource{kwarcpubs.bib}
\addbibresource{extpubs.bib}
\addbibresource{kwarccrossrefs.bib}
\addbibresource{extcrossrefs.bib}
\usepackage{stex-logo}
\usepackage{ctangit}
\usepackage{hyperref}
\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\def\githubissue#1{\cite{sTeX:github:on}, \hyperlink{https://github.com/KWARC/sTeX/issues/#1}{issue #1}}
\begin{document}
\RecordChanges
\DocInput{omtext.dtx}
\end{document}
%</driver>
% \fi
% 
%\CheckSum{411}
% 
% \changes{v0.4}{2008/07/22}{added index markup}
% \changes{v0.4}{2008/09/29}{augmenting the index macros with optional values}
% \changes{v0.6}{2009/07/08}{removing {\texttt{ttin}} {\texttt{{emin}}} and friends, 
%   they were almost never used.}
% \changes{v0.6}{2009/07/08}{renmanig {\texttt{myindex}} to {\texttt{omdoc\@ index}},
%   {\texttt{twin}} to {\texttt{\@ twin}}, and {\texttt{atwin}} to {\texttt{\@ atwin}} to
%   make them packge-local} 
% \changes{v0.7}{2010/02/11}{changing blockquote to sblockquote and inlinequote similarly}
% \changes{v0.9}{2010/05/25}{separated out from \texttt{omdoc.dtx}}
% \changes{v1.0}{2010/06/18}{fixing typos}
% \changes{v1.1}{2015/10/13}{changing \texttt{\textbackslash textleadsto} to
% \texttt{\textbackslash ergo} and defining inverse \texttt{\textbackslash ogre}}
% \changes{v1.1}{2015/11/04}{moving MathHub support out to separate package}
% 
% \GetFileInfo{omtext.sty}
% 
% \MakeShortVerb{\|}
%
% \def\omdoc{OMDoc}
% \def\latexml{{\LaTeX}ML}
% \title{\texttt{omtext}: Semantic Markup for Mathematical Text Fragments in {\LaTeX}\thanks{Version {\fileversion} (last revised
%        {\filedate})}}
%    \author{Michael Kohlhase\\
%            FAU Erlangen-N\"urnberg\\
%            \url{http://kwarc.info/kohlhase}}
% \maketitle
%
% \begin{abstract}
%   The |omtext| package is part of the {\sTeX} collection, a version of {\TeX/\LaTeX} that
%   allows to markup {\TeX/\LaTeX} documents semantically without leaving the document
%   format, essentially turning {\TeX/\LaTeX} into a document format for mathematical
%   knowledge management (MKM).
%
%   This package supplies an infrastructure for writing {\omdoc} text fragments in
%   {\LaTeX}.  
% \end{abstract}
%
%\newpage\tableofcontents\newpage
% 
%\begin{omgroup}[id=sec:STR]{Introduction}
%
%  The |omtext| package supplies macros and environment that allow to mark up mathematical
%  texts in {\sTeX}, a version of {\TeX/\LaTeX} that allows to markup {\TeX/\LaTeX}
%  documents semantically without leaving the document format, essentially turning
%  {\TeX/\LaTeX} into a document format for mathematical knowledge management (MKM). The
%  package supports direct translation to the {\omdoc} format~\cite{Kohlhase:OMDoc1.2}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user]{The User Interface}
% 
% \begin{omgroup}[id=sec:user:options]{Package Options}
% 
%   The |omtext| package takes a single option: \DescribeMacro{showmeta}|showmeta|. If
%   this is set, then the metadata keys are shown (see~\cite{Kohlhase:metakeys:ctan} for
%   details and customization options).
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:omtext]{Mathematical Text}
% 
%   The \DescribeEnv{omtext}|omtext| environment is used for any text fragment that has a
%   contribution to a text that needs to be marked up. It can have a title, which can be
%   specified via the \DescribeMacro{title=}|title| key. Often it is also helpful to
%   annotate the \DescribeMacro{type=}|type| key. The standard relations from rhetorical
%   structure theory |abstract|, |introduction|, |conclusion|, |thesis|, |comment|,
%   |antithesis|, |elaboration|, |motivation|, |evidence|, |transition|, | note|, |annote|
%   are recommended as values. Note that some of them are unary relations like
%   |introduction|, which calls for a target. In this case, a target using the
%   \DescribeMacro{for=}|for| key should be specified. The |transition| relation is
%   special in that it is binary (a ``transition between two statements''), so
%   additionally, a source should be specified using the \DescribeMacro{from=}|from| key.
% 
%   Note that the values of the |title| and |type| keys are often displayed in the
%   text. This can be turned off by setting the \DescribeMacro{display=}|display| key to
%   the value |flow|. Sometimes we want to specify that a text is a continuation of
%   another, this can be done by giving the identifier of this in the
%   \DescribeMacro{continues=}|continues| key.
%
%   Finally, there is a set of keys that pertain to the mathematical formulae in the
%   text. The \DescribeMacro{functions=}|functions| key allows to specify a list of
%   identifiers that are to be interpreted as functions in the generate content
%   markup. The \DescribeMacro{theory=}|theory| specifies a module
%   (see~\cite{KohAmb:smmssl:svn}) that is to be pre-loaded in this one\ednote{this is not
%   implemented yet.} Finally, \DescribeMacro{verbalizes=}|verbalizes| specifies a (more)
%   formal statement (see~\cite{Kohlhase:smms:svn}) that this text verbalizes or
%   paraphrases.\ednote{MK:specify the form of the reference.}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:phrase]{Phrase-Level Markup}
%
%   \DescribeMacro{\phrase} The |phrase| macro allows to mark up phrases with semantic
%   information. It takes an optional |KeyVal| argument with the keys
%   \DescribeMacro{verbalizes=}|verbalizes| and \DescribeMacro{type=}|type| as above and
%   \DescribeMacro{style}|style,| \DescribeMacro{class}|class|,
%   \DescribeMacro{index}|index| that are disregarded in the {\LaTeX}, but copied into the
%   generated content markup.
% 
%   We use the \DescribeMacro{\nlex}|\nlex{|\meta{phrase}|}| for marking up phrases that
%   serve as natural language examples and \DescribeMacro{\nlcex}|\nlcex{|\meta{phrase}|}|
%   for counter-examples (utterances that are not acceptable for some reason). In natural
%   language examples, we sometimes use ``co-reference markers'' to specify the
%   resolution of anaphora and the like. We use the
%   \DescribeMacro{\coreft}|\coreft{|\meta{phrase}|}{|\meta{mark}|}| to mark up the
%   ``target'' of a co-reference and analogously \DescribeMacro{\corefs}|\corefs| for
%   coreference source -- e.g. for an anaphoric reference. The usage is the following:
%   \begin{verbatim}
%   \nlex{If \coreft{a farmer}1 owns \coreft{a donkey}2, 
%            \corefs{he}2 beats \corefs{it}2.}
%   \end{verbatim}
%   is formatted to 
%   \begin{quote}
%     \nlex{If \coreft{a farmer}1 owns \coreft{a donkey}2, \corefs{he}2 beats \corefs{it}2.}
%   \end{quote}
%   
%   \DescribeMacro{\sinlinequote} The |sinlinequote| macro allows to mark up quotes inline
%   and attribute them. The quote itself is given as the argument, possibly preceded by
%   the a specification of the source in a an optional argument. For instance, we would
%   quote Hamlet with
% \begin{verbatim}
% \sinlinequote[Hamlet, \cite{Shak:1603:Hamlet}]{To be or not to be}
% \end{verbatim}
%   which would appear as \sinlinequote[Hamlet, (Shakespeare 1603)]{To be or not to be} in
%   the text. The style in which inline quotations appear in the text can be adapted by
%   specializing the macros \DescribeMacro{\@sinlinequote}|\@sinlinequote| --- for
%   quotations without source and \DescribeMacro{\@@sinlinequote}|\@@sinlinequote| --- for
%   quotations with source.
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:decl]{Declarations (under development)}
%
%   Declarations are special phrases that carry a lot of meaning in mathematics: they
%   introduce and further specify the indentifiers available in formulae.  They are marked
%   up via the \DescribeMacro{\vdec}|\vdec| macro. Inside a declaration we can use the
%   \DescribeMacro{\vids}|\vids| macro to mark up the variable names and
%   \DescribeMacro{\vrest}|\vrest| to mark up the restrictions. In the simplest case we
%   have a single variable as in ``\ldots for all $u$'', which we mark up as.
% \begin{verbatim}
% ... for all \vdec{\vids[u]{$u$}}. 
% \end{verbatim}
%   A more complex example has multiple identifiers embedded in a restriction, as in ``Let
%   $x,y,z\in\mathbb{R}$, such that $x+2y=z$, then \ldots'', which we mark up as
% \begin{verbatim}
% Let \vdec[x,y,z]{\vcond$\minset{x,y,z}\Reals$}, 
%    such that \vrest{$x+2y=z$}}, then \ldots''
% \end{verbatim}
%   \ednote{explain and make better examples}\ednote{talk with Frederic about this see
%   what other examples there are.}\ednote{how do we identify the variables in complex
%   restriction patterns. maybe with LMXref, which we should reinstate for this.}
%   \ednote{document strucdec and impdec}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:block]{Block-Level Markup}
%
%   \DescribeEnv{sblockquote} The |sblockquote| environment is the big brother of the
%   |\sinlinequote| macro. It also takes an optional argument to specify the source. Here
%   the four internal macros \DescribeMacro{\begin@sblockquote}|\begin@sblockquote| to
%       \DescribeMacro{\end@@sblockquote}|\end@@sblockquote| are used for styling and can be
%   adapted by package integrators. Here a quote of Hamlet would marked up as
% \begin{verbatim}
% \begin{sblockquote}[Hamlet, \cite{Shak:1603:Hamlet}]\obeylines
%   To be, or not to be: that is the question:
%   Whether 'tis nobler in the mind to suffer
% \end{sblockquote}
% \end{verbatim}
% and would render as 
% \begin{sblockquote}[Hamlet, (Shakespeare 1603)]\obeylines
%   To be, or not to be: that is the question:
%   Whether 'tis nobler in the mind to suffer
% \end{sblockquote}
% 
% \DescribeMacro{\lec}The |\lec| macro takes one argument and sets it as a comment at the
% end of the line, making sure that if the content is too long it is pushed into a new
% line. We use it internally for placing the of source of the |sblockquote| environment
% above.  The actual appearance of the line end comment is determined by the
% \DescribeMacro{\@@lec}|\@@lec| macro, which can be customized in the document class.
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:user:index]{Index Markup}
%
%   The |omtext| package provides some extensions for the well-known indexing macros of
%   {\LaTeX}. The main reason for introducing these macros is that index markup in
%   {\omdoc} wraps the indexed terms rather than just marking the spot for
%   cross-referencing. Furthermore the index commands only indexes words unless
%   the\DescribeMacro{noindex} |noindex| option is set in the |\usepackage|. The |omtext|
%   package and class make the usual |\index| macro undefined\ednote{implement this and
%     issue the respective error message}.
% 
%     The \DescribeMacro{\indi}|\indi| macro renders a word and marks it for the
%     index. Sometimes, we want to index a slightly different form of the word, e.g. for
%     non-standard plurals: while |\indi{word}s| works fine, we cannot use this for the
%     word ``datum'', which has the plural ``data''. For this we have the macro
%     \DescribeMacro{\aindi}|\aindi|, which takes another argument for the displayed text,
%     allowing us to use |\aindi{data}{datum}|, which prints ``data'' but puts ``datum''
%     into the index.
%   
%     The second set of macros adds an infrastructure for multi-word compounds. Take for
%     instance the compound ``OMDoc document'', which we usually want to add into the
%     index under ``OMDoc'' and
%     ``document''. \DescribeMacro{\indii}|\indii{OMDoc}{document}| is a variant of
%     |\indi| that will do just this. Again, we have a version that prints a variant: This
%     is useful for situations like this the one in Figure~\ref{fig:index-markup}:
% \begin{exfig}
% \begin{verbatim}
% We call group \aindii{Abelian}{Abelian}{group}, iff \ldots
% \end{verbatim}
% \vspace*{-1em}will result in the following
% \begin{quote}
%   We call group \aindii{Abelian}{Abelian}{group}, iff \ldots
% \end{quote}
% and put ``Abelian Group'' into the index.
% \caption{Index markup}\label{fig:index-markup}
% \end{exfig}
% 
% Analogously, there are variants for tree/four-word compounds:
% \DescribeMacro{\indiii}|\indiii|, \DescribeMacro{\aindiii}|\aindiii|,
% \DescribeMacro{\indiv}|\indiv|, and \DescribeMacro{\aindiv}|\indiv|. For instance for
% ``wonderful OMDoc
% document''. \DescribeMacro{\indiii}|\atwin{wonderful}{OMdoc}{document}| will make the
% necessary index entries under ``wonderful'' and ``document''.
% 
% Finally, there are variants \DescribeMacro{\Indi*}|\Indi|, |\Indii|, |\Indiii|, and
% |\Indiv| that print the capitalized version of the word complex, and |\indis|,
% |\indiis|, |\indiiis|, and |\indivs| that add a plurals, and ultimately
% \DescribeMacro{\Indi*}|\Indis|, |\Indiis|, |\indiiis|, and |\Indivs| that print the
% capitalized version of the plural.
%
% All index macros take an optional first keyword argument: If the |loadmodules| key is
% given, we import the module we are in, otherwise all the currently imported modules. We
% do not have to require the module files, since the index is a the end of the
% document. If the |at| key is given, then we use that for sorting in the index.
% \end{omgroup}
%
% \begin{omgroup}[id=sec:user:misc]{Miscellaneous}
%   
%   We supply some text-level shortcuts for mathematical formulations, for instance \hateq
%   for ``this corresponds to'' or \ergo for ``therefore''. They are semantic in the sense
%   that they are used as special words -- not part of formulae, even though they look
%   like mathematical symbols. The following table gives the full set.
%   \begin{center}
%     \DescribeMacro{\hateq}\DescribeMacro {\hatequiv}
%     \DescribeMacro {\ergo}\DescribeMacro{\ogre}
%     \begin{tabular}{|l|l|l|}\hline
%         macro & pres. & stands for \\\hline
%         |\hateq| & \hateq& this corresponds to\\
%         |\hatequiv| & \hatequiv & this statement corresponds to\\
%         |\ergo| &\ergo & therefore\\
%         |\ogre| &\ogre & because of \\\hline
%       \end{tabular}
%     \end{center}
%   \end{omgroup}
% \end{omgroup}
% 
% \begin{omgroup}{Limitations}\label{sec:limitations}
% 
% In this section we document known limitations. If you want to help alleviate them,
% please feel free to contact the package author. Some of them are currently discussed in
% the \sTeX GitHub repository~\cite{sTeX:github:on}. 
% \begin{enumerate}
% \item none reported yet
% \end{enumerate}
% \end{omgroup}
% 
% \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\printbibliography}\newpage
%
% \begin{omgroup}[id=sec:impl]{Implementation}
%
% \begin{omgroup}[id=sec:impl:options]{Package Options}
% 
% We declare some switches which will modify the behavior according to the package
% options. Generally, an option |xxx| will just set the appropriate switches to true
% (otherwise they stay false).\ednote{need an implementation for {\latexml}}
%
%    \begin{macrocode}
%<*package>
\newif\if@omtext@mh@\@omtext@mh@false
\DeclareOption{mh}{\@omtext@mh@true
\PassOptionsToPackage{\CurrentOption}{modules}}
\newif\ifindex\indextrue
\DeclareOption{noindex}{\indexfalse}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{modules}}
\ProcessOptions
\ifindex\makeindex\fi
%    \end{macrocode}
%
%    \begin{macrocode}
\if@omtext@mh@\RequirePackage{omtext-mh}\fi
\RequirePackage{xspace}
\RequirePackage{modules}
\RequirePackage{comment}
\RequirePackage{mdframed}
\RequirePackage{latexsym}
%    \end{macrocode}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:mtxt]{Mathematical Text}
%
%   We define the actions that are undertaken, when the keys are encountered. The first
%   set just records metadata; this is very simple via the |\addmetakey|
%   infrastructure~\ctancite{Kohlhase:metakeys}. Note that we allow math in the |title|
%   field, so we do not declare it to be |Semiverbatim| (indeed not at all, which allows
%   it by default).
%
%    \begin{macrocode}
\srefaddidkey{omtext}
\addmetakey[]{omtext}{functions}
\addmetakey*{omtext}{display}
\addmetakey{omtext}{for}
\addmetakey{omtext}{from}
\addmetakey{omtext}{type}
\addmetakey*{omtext}{title}
\addmetakey*{omtext}{start}
\addmetakey{omtext}{theory}
\addmetakey{omtext}{continues}
\addmetakey{omtext}{verbalizes}
\addmetakey{omtext}{subject}
%    \end{macrocode}
% The next keys handle module loading (see~\ctancite{KohAmb:smmssl}). 
%    \begin{macrocode}
% \ednote{MK: need to implement these in LaTeXML, I wonder whether there is a general
% mechanism like numberit.}\ednote{MK: this needs to be rethought in the light of
% |\usemodule|. It is probably obsolete. Is this used? Is this documented?}
\define@key{omtext}{require}{\requiremodules{#1}{sms}}
\define@key{omtext}{module}{\message{module: #1}\importmodule{#1}\def\omtext@theory{#1}}
%    \end{macrocode}
%
% \begin{macro}{\st@flow}
% We define this macro, so that we can test whether the |display| key has the value |flow|
%    \begin{macrocode}
\def\st@flow{flow}
%    \end{macrocode}
% \end{macro}
%
% We define a switch that allows us to see whether we are inside an |omtext| environment
% or a statement. It will be used to give better error messages for inline statements.
%
%    \begin{macrocode}
\newif\if@in@omtext\@in@omtextfalse
%    \end{macrocode}
%
% \begin{environment}{omtext}
%   The |omtext| environment is different, it does not have a keyword that marks
%   it. Instead, it can have a title, which is used in a similar way. We redefine the
%   |\lec| macro so the trailing |\par| does not get into the way.
%    \begin{macrocode}
\def\omtext@pre@skip{\smallskip}
\def\omtext@post@skip{}
\providecommand{\stDMemph}[1]{\textbf{#1}}
\newenvironment{omtext}[1][]{\@in@omtexttrue%
\bgroup\metasetkeys{omtext}{#1}\sref@label@id{this paragraph}%
\def\lec##1{\@lec{##1}}%
\ifx\omtext@display\st@flow\else\omtext@pre@skip\par\noindent%
\ifx\omtext@title\@empty%
\ifx\omtext@start\@empty\else\stDMemph{\omtext@start}\xspace\fi%
\else\stDMemph{\omtext@title}:\xspace%
\ifx\omtext@start\@empty\else\omtext@start\xspace\fi%
\fi% omtext@title empty
\fi% omtext@display=flow
\ignorespaces}
{\egroup\omtext@post@skip\@in@omtextfalse}
%    \end{macrocode}
% \end{environment}
% \end{omgroup}
%
% \begin{omgroup}[id=sec:impl:phrase]{Phrase-level Markup}
% 
% \begin{macro}{\phrase}
%    For the moment, we do disregard the most of the keys
%    \begin{macrocode}
\srefaddidkey{phrase}
\addmetakey{phrase}{style}
\addmetakey{phrase}{class}
\addmetakey{phrase}{index}
\addmetakey{phrase}{verbalizes}
\addmetakey{phrase}{type}
\addmetakey{phrase}{only}
\newcommand\phrase[2][]{\metasetkeys{phrase}{#1}%
\ifx\prhase@only\@empty\only<\phrase@only>{#2}\else #2\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\coref*}
%    \begin{macrocode}
\providecommand\textsubscript[1]{\ensuremath{_{#1}}}
\newcommand\corefs[2]{#1\textsubscript{#2}}
\newcommand\coreft[2]{#1\textsuperscript{#2}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\n*lex}
%    \begin{macrocode}
\newcommand\nlex[1]{\green{\sl{#1}}}
\newcommand\nlcex[1]{*\green{\sl{#1}}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{sinlinequote}
%    \begin{macrocode}
\def\@sinlinequote#1{``{\sl{#1}}''}
\def\@@sinlinequote#1#2{\@sinlinequote{#2}~#1}
\newcommand\sinlinequote[2][]
{\def\@opt{#1}\ifx\@opt\@empty\@sinlinequote{#2}\else\@@sinlinequote\@opt{#2}\fi}
%    \end{macrocode}
% \end{macro}
% \end{omgroup}
%
% \begin{omgroup}[id=sec:user:decl]{Declarations (under development)}
% 
%   The declaration macros are still under development (i.e. the macros) are still under
%   development and may change at any time. Currently they are completely empty.
% 
% \begin{macrocode}
\newcommand\vdec[2][]{#2}
\newcommand\vrest[2][]{#2}
\newcommand\vcond[2][]{#2}
%    \end{macrocode}
%
% \begin{macro}{\strucdec}
%   \ednote{document above}
%    \begin{macrocode}
\newcommand\strucdec[2][]{#2}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\impdec}
%   \ednote{document above}
%    \begin{macrocode}
\newcommand\impdec[2][]{#2}
%    \end{macrocode}
% \end{macro}
% 
% \end{omgroup}
%
% \begin{omgroup}[id=sec:impl:block]{Block-Level Markup}
%
% \begin{environment}{sblockquote}
%    \begin{macrocode}
\def\begin@sblockquote{\begin{quote}\sl}
\def\end@sblockquote{\end{quote}}
\def\begin@@sblockquote#1{\begin@sblockquote}
\def\end@@sblockquote#1{\def\@@lec##1{\textrm{##1}}\@lec{#1}\end@sblockquote}
\newenvironment{sblockquote}[1][]
  {\def\@opt{#1}\ifx\@opt\@empty\begin@sblockquote\else\begin@@sblockquote\@opt\fi}
  {\ifx\@opt\@empty\end@sblockquote\else\end@@sblockquote\@opt\fi}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{sboxquote}
%    \begin{macrocode}
\newenvironment{sboxquote}[1][]
{\def\@@src{#1}\begin{mdframed}[leftmargin=.5cm,rightmargin=.5cm]}
{\@lec{\textrm\@@src}\end{mdframed}}
%    \end{macrocode}
% \end{environment}
% 
% The line end comment macro makes sure that it will not be forced on the next line unless
% necessary.
% \begin{macro}{\lec}
%   The actual appearance of the line end comment is determined by the |\@@lec| macro,
%   which can be customized in the document class. The basic one here is provided so that
%   it is not missing.
%    \begin{macrocode}
\providecommand{\@@lec}[1]{(#1)}
\def\@lec#1{\strut\hfil\strut\null\nobreak\hfill\@@lec{#1}}
\def\lec#1{\@lec{#1}\par}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\my*graphics}
%   We set up a special treatment for including graphics to respect the intended {\omdoc}
%   document structure. The main work is done in the transformation stylesheet though.
%    \begin{macrocode}
\newcommand\mygraphics[2][]{\includegraphics[#1]{#2}}
\newcommand\mycgraphics[2][]{\begin{center}\mygraphics[#1]{#2}\end{center}}
\newcommand\mybgraphics[2][]{\fbox{\mygraphics[#1]{#2}}}
\newcommand\mycbgraphics[2][]{\begin{center}\fbox{\mygraphics[#1]{#2}}\end{center}}
%    \end{macrocode}
% \end{macro}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:index]{Index Markup}
%
% \begin{macro}{\omdoc@index*}
%   these are the main internal indexing commands -- dividing them into four macros is awful,
%   but I did not get list processing running. It makes sure that the modules necessary
%   for interpreting the math in the index entries are loaded. If the |loadmodules| key is
%   given, we import the module we are in otherwise all the currently imported modules. We
%   do not have to require the module files, since the index is a the end of the
%   document. If the |at| key is given, then we use that for sorting in the index.
%    \begin{macrocode}
\addmetakey{omdoc@index}{at}
\addmetakey[false]{omdoc@index}{loadmodules}[true]
\newcommand\omdoc@indexi[2][]{\ifindex%
\metasetkeys{omdoc@index}{#1}%
\@bsphack\begingroup\@sanitize%
\protected@write\@indexfile{}{\string\indexentry%
{\ifx\omdoc@index@at\@empty\else\omdoc@index@at @\fi%
\ifx\omdoc@index@loadmodules\@true%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#2}%
\else #2\fi% loadmodules 
}{\thepage}}%
\endgroup\@esphack\fi}%ifindex
\newcommand\omdoc@indexii[3][]{\ifindex%
\metasetkeys{omdoc@index}{#1}%
\@bsphack\begingroup\@sanitize%
\protected@write\@indexfile{}{\string\indexentry%
{\ifx\omdoc@index@at\@empty\else\omdoc@index@at @\fi%
\ifx\omdoc@index@loadmodules\@true%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#2}!%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#3}%
\else #2!#3\fi% loadmodules 
}{\thepage}}%
\endgroup\@esphack\fi}%ifindex
\newcommand\omdoc@indexiii[4][]{\ifindex%
\metasetkeys{omdoc@index}{#1}%
\@bsphack\begingroup\@sanitize%
\protected@write\@indexfile{}{\string\indexentry%
{\ifx\omdoc@index@at\@empty\else\omdoc@index@at @\fi%
\ifx\omdoc@index@loadmodules\@true%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#2}!%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#3}!%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#4}%
\else #2!#3!#4\fi% loadmodules 
}{\thepage}}%
\endgroup\@esphack\fi}%ifindex
\newcommand\omdoc@indexiv[5][]{\ifindex%
\metasetkeys{omdoc@index}{#1}%
\@bsphack\begingroup\@sanitize%
\protected@write\@indexfile{}{\string\indexentry%
{\ifx\omdoc@index@at\@empty\else\omdoc@index@at @\fi%
\ifx\omdoc@index@loadmodules\@true%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#2}!%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#3}!%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#4}%
\string\withusedmodules{\@ifundefined{mod@id}\used@modules\mod@id}{#5}%
\else #2!#3!#4!#5\fi% loadmodules 
}{\thepage}}%
\endgroup\@esphack\fi}%ifindex
%    \end{macrocode}
% \end{macro}
% 
% Now, we make two interface macros that make use of this: 
%
% \begin{macro}{\*indi*}
%    \begin{macrocode}
\newcommand\aindi[3][]{{#2}\omdoc@indexi[#1]{#3}}
\newcommand\indi[2][]{{#2}\omdoc@indexi[#1]{#2}}
\newcommand\indis[2][]{{#2}\omdoc@indexi[#1]{#2s}}
\newcommand\Indi[2][]{{\captitalize{#2}}\omdoc@indexi[#1]{#2}}
\newcommand\Indis[2][]{{\capitalize{#2}}\omdoc@indexi[#1]{#2s}}

\newcommand\@indii[3][]{\omdoc@indexii[#1]{#2}{#3}\omdoc@indexii[#1]{#3}{#2}}
\newcommand\aindii[4][]{#2\@indii[#1]{#3}{#4}}
\newcommand\indii[3][]{{#2 #3}\@indii[#1]{#2}{#3}}
\newcommand\indiis[3][]{{#2 #3s}\@indii[#1]{#2}{#3}}
\newcommand\Indii[3][]{{\captitalize{#2 #3}}\@indii[#1]{#2}{#3}}
\newcommand\Indiis[3][]{{\capitalize{#2 #3}}\@indii[#1]{#2}{#3}}

\newcommand\@indiii[4][]{\omdoc@indexiii[#1]{#2}{#3}{#4}\omdoc@indexii[#1]{#3}{#2 (#4)}}
\newcommand\aindiii[5][]{{#2}\@indiii[#1]{#3}{#4}{#5}}
\newcommand\indiii[4][]{{#2 #3 #4}\@indiii[#1]{#2}{#3}{#4}}
\newcommand\indiiis[4][]{{#2 #3 #4s}\@indiii[#1]{#2}{#3}{#4}}
\newcommand\Indiii[4][]{\captitalize{#2 #3 #4}\@indiii[#1]{#2}{#3}{#4}}
\newcommand\Indiiis[4][]{\capitalize{#2 #3 #4s}\@indiii[#1]{#2}{#3}{#4}}

\newcommand\@indiv[5][]{\omdoc@indexiv[#1]{#2}{#3}{#4}{#5}}
\newcommand\aindiv[6][]{#2\@indiv[#1]{#3}{#4}{#5}{#6}}
\newcommand\indiv[5][]{{#2 #3 #4 #5}\@indiv[#1]{#2}{#3}{#4}{#5}}
\newcommand\indivs[5][]{{#2 #3 #4 #5s}\@indiv[#1]{#2}{#3}{#4}{#5}}
\newcommand\Indiv[5][]{\capitalize{#2 #3 #4 #5s}\@indiv[#1]{#2}{#3}{#4}{#5}}
\newcommand\Indivs[5][]{\capitalize{#2 #3 #4 #5s}\@indiv[#1]{#2}{#3}{#4}{#5}}
%    \end{macrocode}
% \end{macro}
% \end{omgroup}
% 
% \begin{omgroup}[id=sec:impl:misc]{Miscellaneous}
%   Some shortcuts that use math symbols but are not mathematical at all; in particular,
%   they should not be translated by {\latexml}.
%    \begin{macrocode}
\newcommand\hateq{\ensuremath{\widehat=}\xspace}
\newcommand\hatequiv{\ensuremath{\widehat\equiv}\xspace}
\@ifundefined{ergo}%
{\newcommand\ergo{\ensuremath{\leadsto}\xspace}}%
{\renewcommand\ergo{\ensuremath{\leadsto}\xspace}}%
\newcommand{\reflect@squig}[2]{\reflectbox{$\m@th#1\rightsquigarrow$}}%
\newcommand\ogre{\ensuremath{\mathrel{\mathpalette\reflect@squig\relax}}\xspace}%
\newcommand\notergo{\ensuremath{\not\leadsto}}
\newcommand\notogre{\ensuremath{\not\mathrel{\mathpalette\reflect@squig\relax}}\xspace}%
%    \end{macrocode}
%
% \end{omgroup}
%
% \begin{omgroup}{Deprecated Functionality}\label{sec:deprecated}
%
% In this section we centralize old interfaces that are only partially supported any
% more. 
% \begin{macro}{\*def*}
%    \begin{macrocode}
\newcommand\indextoo[2][]{\indi[#1]{#2}%
\PackageWarning{omtext}{\protect\indextoo\space is deprecated, use \protect\indi\space instead}}
\newcommand\indexalt[2][]{\aindi[#1]{#2}%
\PackageWarning{omtext}{\protect\indextoo\space is deprecated, use \protect\aindi\space instead}}
\newcommand\twintoo[3][]{\indii[#1]{#2}{#3}%
\PackageWarning{omtext}{\protect\twintoo\space is deprecated, use \protect\indii\space instead}}
\newcommand\twinalt[3][]{\aindii[#1]{#2}{#3}%
\PackageWarning{omtext}{\protect\twinalt\space is deprecated, use \protect\aindii\space instead}}
\newcommand\atwintoo[4][]{\indiii[#1]{#2}{#3}{#4}%
\PackageWarning{omtext}{\protect\atwintoo\space is deprecated, use \protect\indiii\space instead}}
\newcommand\atwinalt[4][]{\aindii[#1]{#2}{#3}{#4}%
\PackageWarning{omtext}{\protect\atwinalt\space is deprecated, use \protect\aindiii\space instead}}
%</package>
%    \end{macrocode}
% \end{macro}
% \end{omgroup}
% \end{omgroup}
% \Finale
\endinput
% \iffalse
%%% Local Variables: 
%%% mode: doctex
%%% TeX-master: t
%%% End: 
% \fi
% LocalWords:  GPL structuresharing STR omdoc dtx stex CPERL LoadClass url dc filedate sl 
% LocalWords:  RequirePackage RegisterNamespace namespace xsl DocType ltxml dtd annote mh
% LocalWords:  ltx DefEnvironment beforeDigest AssignValue inPreamble getGullet indexalt
% LocalWords:  afterDigest keyval omgroup DefKeyVal Semiverbatim KeyVal regexp indexalt
% LocalWords:  OptionalKeyVals DefParameterType IfBeginFollows skipSpaces CMP rangle rel
% LocalWords:  ifNext DefMacro needwrapper unlist DefConstructor omtext bgroup rangle baz
% LocalWords:  useCMPItemizations RefStepItemCounter egroup beginItemize li di makeindex
% LocalWords:  beforeDigestEnd dt autoclose ul ol dl env showignores srcref def st@flow
% LocalWords:  afterOpen LastSeenCMP autoClose DefCMPEnvironment proto ToString KeyVals
% LocalWords:  addAttribute nlex nlcex omdocColorMacro args tok MergeFont qw rm XPointer
% LocalWords:  TokenizeInternal toString isMath foreach maybeCloseElement id'd endinput
% LocalWords:  autoOpen minipage footnotesize scriptsize numberIt whatsit href HorIacJuc
% LocalWords:  getAttribute setAttribute OMDoc RelaxNGSchema noindex xml lec sc cscpnrr11
% LocalWords:  Subsubsection useDefaultItemizations refundefinedtrue sblockquote foobar
% LocalWords:  DefCMPConstructor sinlinequote idx idt ide idp emph  extrefs sref mhrepos
% LocalWords:  flushleft flushright DeclareOption PassOptions undef cls iffalse mathhub
% LocalWords:  ProcessOptions subparagraph ignoresfalse ignorestrue raisebox tr finalpath
% LocalWords:  texorpdfstring latexml texttt fileversion maketitle newpage iff mh-variant
% LocalWords:  tableofcontents newpage ednote obeylines usepackage indextoo Cwd coreft
% LocalWords:  indextoo twintoo twintoo exfig vspace twinalt ldots ttin emin importmodule
% LocalWords:  renmanig myindex atwin atwin packge-local blockquote inlinequote coreft
% LocalWords:  atwintoo atwinalt atwinalt printbibliography impl cwd newif ifx mhgraphics
% LocalWords:  ifindex indextrue indexfalse srefaddidkey smallskip showmeta importmodules
% LocalWords:  providecommand stDMemph textbf newenvironment hfil showmeta NeedsTeXFormat
% LocalWords:  noindent ignorespaces newcommand nobreak hfill hbox mygraphics mhcgraphics
% LocalWords:  includegraphics mycgraphics mybgraphics fbox adjectivized hspace corefs
% LocalWords:  printindex jobname.ind jobname.ind omspace footnotemark thead mhcgraphics
% LocalWords:  footnotetext findnodes doctex textsf langle textsf langle funval corefs
% LocalWords:  metakeys funsymbs addmetakey metasetkeys startemph textsl textit mdframed
% LocalWords:  compactenum ifundefined localname localname xspace ctancite mhcurrentrepos
% LocalWords:  KohAmb smmssl requiremodules prhase bsphack begingroup thepage mh-variants
% LocalWords:  indexentry endgroup esphack SOURCEFILE baselocal BASELOCAL importmhmodule
% LocalWords:  mh@currentrepos mhbgraphics co-rerefence usemodule coref textsubscript
% LocalWords:  ensuremath textsuperscript sboxquote leftmargin rightmargin mycbgraphics
% LocalWords:  mhcbgraphics textleadsto customization specializing customized behavior
% LocalWords:  flexiformal latexsym itemize loadmodules recognize hateq hatequiv equiv
% LocalWords:  leadsto renewcommand reflect@squig reflectbox m@th rightsquigarrow
% LocalWords:  mathrel mathpalette
% \endinput
% Local Variables:
% mode: doctex
% TeX-master: t
% End:
