Skip to content

Instantly share code, notes, and snippets.

@michal-h21
Last active August 30, 2015 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michal-h21/6104f70091e0f4fead36 to your computer and use it in GitHub Desktop.
Save michal-h21/6104f70091e0f4fead36 to your computer and use it in GitHub Desktop.
LaTeX to TEI conversion. context: http://tex.stackexchange.com/q/263548/2891
\renewcommand\SetSemanticMarkup[1]{\typeout{semantic markup}}
\Preamble{xhtml,tei}
\Configure{VERSION}{}
\Configure{DOCTYPE}{}
\Configure{HTML}{\HCode{<TEI xmlns="http://www.tei-c.org/ns/1.0">\Hnewline}}{\HCode{\Hnewline</TEI>}}
\ifdefined\ifmathml\else
\newif\ifmathml
\mathmlfalse
\fi
\csname :CheckOption\endcsname{mathml}\csname if:Option\endcsname\mathmltrue\fi
\begin{document}
\EndPreamble
\documentclass{article}
\title{hello world}
\author{Some Author}
\usepackage{semanticmarkup}
\SetSemanticMarkup {
\term = \textit,
\scare = \enquote,
\socalled = \enquote,
\q = \enquote,
}
\begin{document}
\maketitle
hi
\term{hi}
\scare{hi}
\socalled{hi}
\term{Musica ficta} is the practice of adding accidentals where they are not notated.
The teacher told us, \q{Always sing F-sharp before a cadence on G\@!}
\end{document}
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader type="text" status="new"><fileDesc> <titleStmt>
<title>hello world</title>
<author>Some Author</author>
</titleStmt>
<publicationStmt> <p></p> </publicationStmt>
<sourceDesc><p>sample.xml from sample.tex (TeX4ht, 2015-08-29 00:47:00)</p></sourceDesc>
</fileDesc>
<revisionDesc><list type="simple"><item></item></list></revisionDesc>
</teiHeader><text><front>
hi
<!--l. 16--><div type="p"><p> <term>hi</term>
</p></div><!--l. 18--><div type="p"><p> <scare>&#8220;hi&#8221;</scare>
</p></div><!--l. 20--><div type="p"><p> <socalled>&#8220;hi&#8221;</socalled>
</p></div><!--l. 22--><div type="p"><p> <term>Musica ficta</term> is the practice of adding accidentals where they are not
notated. The teacher told us, <q>&#8220;Always sing F-sharp before a cadence on
G!&#8221;</q>
</p></div></front><body><p></p></body></text>
</TEI>
\ExplSyntaxOn
\seq_map_inline:Nn \teicommands {
\pend:defI#1{\HCode{<\cs_to_str:N#1>}}
\append:defI#1{\HCode{</\cs_to_str:N#1>}}
}
\ExplSyntaxOff
\ProvidesPackage{semanticmarkup}
\RequirePackage{xparse}
\ExplSyntaxOn
\seq_new:N \teicommands
\NewDocumentCommand \SetSemanticMarkup { m }
{
\clist_map_inline:nn { #1 }
{
\SetEquivalent{ ##1 }
}
}
\NewDocumentCommand{\SetEquivalent}{ >{\SplitArgument{1}{=}} m }
{
\cashner_set_equivalent:nn #1
}
\cs_new_protected:Nn \cashner_set_equivalent:nn
{
\seq_gput_right:Nn \teicommands {#1}
\cs_new_eq:NN #1 #2
}
\ExplSyntaxOff
\usepackage{csquotes}
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment