Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add handling of double underscores in generated html #160

Merged
merged 11 commits into from
Sep 24, 2023
4 changes: 3 additions & 1 deletion src/mmhlpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ H("interpreted by / SYMBOLS, / LABELS, and / BIB_REFS respectively, escape");
H("them with \"``\", \"~~\", and \"[[\" in the input file. Literal \"`\"");
H("must always be escaped even if / SYMBOLS is omitted, because the");
H("algorithm will still use \"`...`\" to avoid interpreting special");
H("characters in math symbols.");
H("characters in math symbols. Similarly, use a double underscore to");
H("display one underscore \"_\" and not trigger an italic font or");
H("subscripts.");
H("");
}

Expand Down
21 changes: 21 additions & 0 deletions src/mmwtex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,27 @@ flag printTexComment(vstring commentPtr, flag htmlCenterFlag,
if (!strcmp(mid(cmt, pos2 + 2, 2), "mm")) {
continue;
}
// Double-underscore handling: double-underscores are "escaped
// underscores", so replace a double-underscore with a single
// underscore and do not modify italic or subscript.
if (cmt[pos1] == '_') {
if (g_htmlFlag) { // HTML
let(&cmt, cat(left(cmt, pos1), // Skip (delete) "_"
right(cmt, pos1 + 2), NULL));
let(&cmtMasked, cat(left(cmtMasked, pos1), // Skip (delete) "_"
right(cmtMasked, pos1 + 2), NULL));
pos1 ++; // Adjust for 1 extra char '_'
} else { // LaTeX
let(&cmt, cat(left(cmt, pos1 - 1), // Skip (delete) "_"
"\\texttt{\\_}",
right(cmt, pos1 + 2), NULL));
let(&cmtMasked, cat(left(cmtMasked, pos1 - 1), // Skip (delete) "_"
"\\texttt{\\_}",
right(cmtMasked, pos1 + 2), NULL));
pos1 = pos1 + 11; // Adjust for 11 extra chars "\texttt{\_}"
}
continue;
} // End of double-underscore handling

// Opening "_" must be <whitespace>_<alphanum> for <I> tag
if (pos1 > 1) {
Expand Down
105 changes: 105 additions & 0 deletions tests/underscores.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
MM> READ "underscores.mm"
Reading source file "underscores.mm"... 193 bytes
193 bytes were read into the source buffer.
The source has 2 statements; 1 are $a and 0 are $p.
SET EMPTY_SUBSTITUTION was turned ON (allowed) for this database.
No errors were found. However, proofs were not checked. Type VERIFY PROOF *
if you want to check them.
MM> Continuous scrolling is now in effect.
MM> Creating HTML file "b.html"...
Reading definitions from $t statement of underscores.mm...
1 typesetting statements were read from "underscores.mm".
MM> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML LANG="EN-US">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
<!--
img { margin-bottom: -4px }
.r { font-family: "Arial Narrow";
font-size: x-small;
}
.i { font-family: "Arial Narrow";
font-size: x-small;
color: gray;
}
-->
</STYLE>

<TITLE>b - Metamath Test Page</TITLE>
<LINK REL="shortcut icon" HREF="favicon.ico" TYPE="image/x-icon">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
<TR>
<TD ALIGN=LEFT VALIGN=TOP WIDTH="25%"><A HREF=
"mmset.html"><IMG SRC="mm.gif"
BORDER=0
ALT="MTP Home"
TITLE="MTP Home"
HEIGHT=32 WIDTH=32 ALIGN=TOP STYLE="margin-bottom:0px"></A>
</TD>
<TD ALIGN=CENTER COLSPAN=2 VALIGN=TOP><FONT SIZE="+3" COLOR="#006633"><B>
Metamath Test Page
</B></FONT></TD>
<TD ALIGN=RIGHT VALIGN=TOP WIDTH="25%">
<FONT SIZE=-1 FACE=sans-serif>
<A HREF="b.html">
&lt; Wrap</A>&nbsp;&nbsp;
<A HREF="b.html">Wrap &gt;</A>
</FONT><FONT FACE=sans-serif SIZE=-2>
<BR><A HREF="mmtheorems1.html#b">Nearby theorems</A>
</FONT>
</TD>
</TR>
<TR>
<TD COLSPAN=2 ALIGN=LEFT VALIGN=TOP><FONT SIZE=-2
FACE=sans-serif>
<A HREF="../mm.html">Mirrors</A>&nbsp; &gt;
&nbsp;<A HREF="../index.html">Home</A>&nbsp; &gt;
&nbsp;<A HREF="mmset.html">MTP Home</A>&nbsp; &gt;
&nbsp;<A HREF="mmtheorems.html">Th. List</A>&nbsp; &gt;
&nbsp;b
</FONT>
</TD>
<TD COLSPAN=2 ALIGN=RIGHT VALIGN=TOP>
<FONT SIZE=-2 FACE=sans-serif>

</FONT>
</TD>
</TR>
</TABLE>
<HR NOSHADE SIZE=1>
<CENTER><B><FONT SIZE="+1">Syntax Definition <FONT
COLOR="#006633">b</FONT></FONT></B>&nbsp;<SPAN CLASS=r
STYLE="color:#FB0000">1</SPAN></CENTER>
<CENTER><TABLE><TR><TD ALIGN=LEFT><B>Description: </B>This is <I>italic</I> and
the command &quot;MM-PA&gt; MINIMIZE_WITH *&quot; and a
sub<SUB><FONT SIZE="-1">script</FONT></SUB>.</TD></TR></TABLE></CENTER>

<CENTER><TABLE BORDER CELLSPACING=0 BGCOLOR="#EEFFFA"
SUMMARY="Assertion">
<CAPTION><B>Assertion</B></CAPTION>
<TR><TH>Ref
</TH><TH>Expression</TH></TR>
<TR ALIGN=LEFT><TD><FONT COLOR="#006633"><B>b</B></FONT></TD><TD>
<SPAN >a</SPAN></TD></TR>
</TABLE></CENTER>


<HR NOSHADE SIZE=1>
</TABLE></CENTER>
<TABLE BORDER=0 WIDTH="100%">
<TR><TD WIDTH="25%">&nbsp;</TD>
<TD ALIGN=CENTER VALIGN=BOTTOM>
<FONT SIZE=-2 FACE=sans-serif>
Copyright terms:
<A HREF="../copyright.html#pd">Public domain</A>
</FONT></TD><TD ALIGN=RIGHT VALIGN=BOTTOM WIDTH="25%">
<FONT SIZE=-2 FACE=sans-serif>
<A HREF="http://validator.w3.org/check?uri=referer">
W3C validator</A>
</FONT></TD></TR></TABLE>
</BODY></HTML>
2 changes: 2 additions & 0 deletions tests/underscores.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
show statement b/alt_html
"cat b.html"
10 changes: 10 additions & 0 deletions tests/underscores.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$c a $.

$( This is _italic_ and the command "MM-PA> MINIMIZE__WITH *" and a
sub_script. $)
b $a a $.

$( $t
htmldef "a" as "a";
althtmldef "a" as "a";
latexdef "a" as "a"; $)
Loading