-
Notifications
You must be signed in to change notification settings - Fork 25
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
Structured Typesetting (STS) generation #9
base: master
Are you sure you want to change the base?
Changes from 8 commits
7742b5c
8af50bc
eedc22f
9202215
991bd6c
1a66907
f3ae0fa
2a870d8
ea0bde7
59c02a3
6371dc7
dcbc83a
c5925cb
e5f602f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.o | ||
metamath | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
memory management; converts between proof formats | ||
mmhlpa.c - The help file, part 1. | ||
mmhlpb.c - The help file, part 2. | ||
mmhtbl.c - Hashtable implementation | ||
mminou.c - Basic input and output interface | ||
mmmaci.c - THINK C Macintosh interface (obsolete) | ||
mmpars.c - Parses the source file | ||
|
@@ -29,6 +30,7 @@ | |
mmveri.c - Proof verifier for source file | ||
mmvstr.c - BASIC-like string functions | ||
mmwtex.c - LaTeX/HTML source generation | ||
mmwsts.c - STS source generation | ||
mmword.c - File revision utility (for TOOLS> UPDATE) (not generally useful) | ||
*/ | ||
|
||
|
@@ -57,7 +59,16 @@ | |
|
||
|
||
|
||
#define MVERSION "0.198 7-Aug-2021" | ||
#define MVERSION "0.199 24-Dec-2021" | ||
/* 0.199 tar 24-Dec-2021 mmwsts.c and others - Merge STS source generation code | ||
originally developped in July 2017. STS stands for Structured TypeSetting and | ||
can be used to generate MathML, which can in turn be postprocessed by MathJAX | ||
to output mathematical typesetting (this includes indices, exponents, summands | ||
and integrals with sets specifed below the sign, square roots with overhangs, | ||
fraction bars, sized parentheses, etc.) The code introduces a new / STS flag | ||
as a third alternative to / HTML and / ALT_HTML for HTML page generation, and | ||
a / VERIFY STS option to only check the integrity of the external STS command | ||
file. */ | ||
/* 0.198 nm 7-Aug-2021 mmpars.c - Fix cosmetic bug in WRITE SOURCE ... /REWRAP | ||
that prevented end of sentence (e.g. period) from appearing in column 79, | ||
thus causing some lines to be shorter than necessary. */ | ||
|
@@ -704,6 +715,7 @@ | |
#include "mmunif.h" | ||
#include "mmword.h" | ||
#include "mmwtex.h" | ||
#include "mmwsts.h" | ||
#ifdef THINK_C | ||
#include "mmmaci.h" | ||
#endif | ||
|
@@ -2375,14 +2387,25 @@ void command(int argc, char *argv[]) | |
g_htmlFlag = 1; | ||
/* If not specified, for backwards compatibility in scripts | ||
leave g_altHtmlFlag at current value */ | ||
/* 7-Jul-17 - MathML/STS handling */ | ||
if (switchPos("/ HTML") != 0) { | ||
if (switchPos("/ ALT_HTML") != 0) { | ||
print2("?Please specify only one of / HTML and / ALT_HTML.\n"); | ||
if (switchPos("/ ALT_HTML") != 0 || switchPos("/ STS") != 0 ) { | ||
print2("?Please specify only one of / HTML , / ALT_HTML and / STS.\n"); | ||
Comment on lines
+2141
to
+2142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wlammen wrote:
I don't think this is called 3 times. There are 3 else..if branches, and it is called one time in each, to ensure only one HTML output formatting option is chosen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. It still looks awkward since the call and the parameter is coded several times. |
||
continue; | ||
} | ||
g_altHtmlFlag = 0; | ||
} else { | ||
if (switchPos("/ ALT_HTML") != 0) g_altHtmlFlag = 1; | ||
} else if (switchPos("/ ALT_HTML") != 0) { | ||
if (switchPos ("/ STS") != 0) { | ||
print2 ("?Please specify only one of / HTML , / ALT_HTML and / STS.\n"); | ||
continue; | ||
} | ||
g_altHtmlFlag = 1; | ||
} else if (switchPos ("/ STS") != 0) { | ||
stsFlag = 1; | ||
let(&stsOutput, g_fullArg[5]); | ||
|
||
/* Parse the STS rules corresponding to the expected output . */ | ||
parseSTSRules(stsOutput); | ||
} | ||
|
||
if (2/*error*/ == readTexDefs(0 /* 1 = check errors only */, | ||
|
@@ -2947,6 +2970,8 @@ void command(int argc, char *argv[]) | |
switchPos("/ HTML") | ||
|| switchPos("/ BRIEF_HTML") | ||
|| switchPos("/ ALT_HTML") | ||
/* 7-Jul-2017 added MathML/STS */ | ||
|| switchPos("/ STS") | ||
|| switchPos("/ BRIEF_ALT_HTML"))) { | ||
/* Special processing for the / HTML qualifiers - for each matching | ||
statement, a .html file is opened, the statement is output, | ||
|
@@ -2959,6 +2984,8 @@ void command(int argc, char *argv[]) | |
i = 5; /* # arguments with only / HTML or / ALT_HTML */ | ||
if (noVersioning) i = i + 2; | ||
if (switchPos("/ TIME")) i = i + 2; | ||
/* 7-Jul-2017 added MathML/STS : one more argument for STS */ | ||
if (switchPos("/ STS")) i = i + 1; | ||
if (g_rawArgs != i) { | ||
printLongLine(cat("?The HTML qualifiers may not be combined with", | ||
" others except / NO_VERSIONING and / TIME.\n", NULL), " ", " "); | ||
|
@@ -3011,6 +3038,15 @@ void command(int argc, char *argv[]) | |
g_altHtmlFlag = 0; | ||
} | ||
|
||
/* 7-Jul-2017 added MathML/STS */ | ||
if (switchPos("/ STS")) { | ||
stsFlag = 1; | ||
let(&stsOutput, g_fullArg[5]); | ||
|
||
/* Parse the STS rules corresponding to the expected output. */ | ||
parseSTSRules(stsOutput); | ||
} | ||
|
||
q = 0; | ||
|
||
/* Special feature: if the match statement starts with "*", we | ||
|
@@ -3082,20 +3118,32 @@ void command(int argc, char *argv[]) | |
let(&g_texFileName, cat(g_Statement[g_showStatement].labelName, ".html", | ||
NULL)); | ||
} | ||
print2("Creating HTML file \"%s\"...\n", g_texFileName); | ||
g_texFilePtr = fSafeOpen(g_texFileName, "w", /* 17-Jul-2019 nm */ | ||
noVersioning /*noVersioningFlag*/); | ||
/****** old code before 17-Jul-2019 ******* | ||
if (switchPos("/ NO_VERSIONING") == 0) { | ||
g_texFilePtr = fSafeOpen(g_texFileName, "w", 0/@noVersioningFlag@/); | ||
} else { | ||
/@ 6-Jul-2008 nm Added / NO_VERSIONING @/ | ||
/@ Don't create the backup versions ~1, ~2,... @/ | ||
g_texFilePtr = fopen(g_texFileName, "w"); | ||
if (!g_texFilePtr) print2("?Could not open the file \"%s\".\n", | ||
g_texFileName); | ||
/* 29-Sep-17 Thierry Arnoux - Post processing (for pre-rendering) */ | ||
if(stsFlag && strlen(postProcess) != 0) { | ||
vstring pipeCommand = ""; | ||
print2("Creating and processing HTML file \"%s\"...\n", g_texFileName); | ||
let(&pipeCommand, cat(postProcess, " > ", g_texFileName, NULL)); | ||
g_texFilePtr = popen(pipeCommand, "w"); | ||
if (!g_texFilePtr) print2("?Could not execute the command \"%s\".\n", | ||
pipeCommand); | ||
let(&pipeCommand, ""); | ||
} | ||
else { | ||
print2("Creating HTML file \"%s\"...\n", g_texFileName); | ||
g_texFilePtr = fSafeOpen(g_texFileName, "w", /* 17-Jul-2019 nm */ | ||
noVersioning /*noVersioningFlag*/); | ||
/****** old code before 17-Jul-2019 ******* | ||
if (switchPos("/ NO_VERSIONING") == 0) { | ||
g_texFilePtr = fSafeOpen(g_texFileName, "w", 0/@noVersioningFlag@/); | ||
} else { | ||
/@ 6-Jul-2008 nm Added / NO_VERSIONING @/ | ||
/@ Don't create the backup versions ~1, ~2,... @/ | ||
g_texFilePtr = fopen(g_texFileName, "w"); | ||
if (!g_texFilePtr) print2("?Could not open the file \"%s\".\n", | ||
g_texFileName); | ||
} | ||
********* end of old code before 17-Jul-2019 *******/ | ||
} | ||
********* end of old code before 17-Jul-2019 *******/ | ||
if (!g_texFilePtr) goto htmlDone; /* Couldn't open it (err msg was | ||
provided) */ | ||
g_texFileOpenFlag = 1; | ||
|
@@ -3230,7 +3278,10 @@ void command(int argc, char *argv[]) | |
if (!instr(1, str3, cat(" ", str1, " ", NULL))) { | ||
let(&str3, cat(str3, " ", str1, " ", NULL)); | ||
let(&str2, ""); | ||
str2 = tokenToTex(g_MathToken[(g_Statement[i].mathString)[j] | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str2 = stsToken((g_Statement[i].mathString)[j], i); | ||
else | ||
str2 = tokenToTex(g_MathToken[(g_Statement[i].mathString)[j] | ||
].tokenName, i/*stmt# for error msgs*/); | ||
/* 2/9/02 Skip any tokens (such as |- in QL Explorer) that | ||
may be suppressed */ | ||
|
@@ -3380,7 +3431,8 @@ void command(int argc, char *argv[]) | |
ABORT_S: | ||
/*** Close the html file ***/ | ||
printTexTrailer(1 /*texHeaderFlag*/); | ||
fclose(g_texFilePtr); | ||
if(stsFlag && strlen(postProcess) != 0) pclose(g_texFilePtr); | ||
else fclose(g_texFilePtr); | ||
g_texFileOpenFlag = 0; | ||
let(&g_texFileName,""); | ||
|
||
|
@@ -8093,6 +8145,13 @@ void command(int argc, char *argv[]) | |
continue; | ||
} | ||
|
||
if (cmdMatches("VERIFY STS")) { | ||
/* 12-Dec-17 - Go through all non-definition axioms, | ||
* and check whether there is a corresponding STS scheme */ | ||
verifySts(g_fullArg[2]); | ||
continue; | ||
} | ||
|
||
print2("?This command has not been implemented.\n"); | ||
continue; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ flag processCommandLine(void) | |
"MARKUP|ASSIGN|REPLACE|MATCH|UNIFY|LET|INITIALIZE|DELETE|IMPROVE|", | ||
/* 11-Sep-2016 nm Added EXPAND */ | ||
"MINIMIZE_WITH|EXPAND|UNDO|REDO|SAVE|DEMO|INVOKE|CLI|EXPLORE|TEX|", | ||
"LATEX|HTML|COMMENTS|BIBLIOGRAPHY|MORE|", | ||
"LATEX|HTML|STS|COMMENTS|BIBLIOGRAPHY|MORE|", | ||
"TOOLS|MIDI|$|<$>", NULL))) goto pclbad; | ||
if (cmdMatches("HELP OPEN")) { | ||
/*if (!getFullArg(2, "LOG|TEX|HTML|<LOG>")) goto pclbad;*/ | ||
|
@@ -124,7 +124,7 @@ flag processCommandLine(void) | |
goto pclgood; | ||
} | ||
if (cmdMatches("HELP VERIFY")) { | ||
if (!getFullArg(2, "PROOF|MARKUP|<PROOF>")) | ||
if (!getFullArg(2, "PROOF|MARKUP|STS|<PROOF>")) | ||
goto pclbad; | ||
goto pclgood; | ||
} | ||
|
@@ -577,8 +577,20 @@ flag processCommandLine(void) | |
if (!getFullArg(i, cat( | ||
"FULL|COMMENT|TEX|OLD_TEX|HTML|ALT_HTML|TIME|BRIEF_HTML", | ||
/* 12-May-2009 sa Added MNEMONICS */ | ||
"|BRIEF_ALT_HTML|MNEMONICS|NO_VERSIONING|<FULL>", NULL))) | ||
"|BRIEF_ALT_HTML|MNEMONICS|NO_VERSIONING|<FULL>" | ||
/* 7-Jul-2017 added MATHML/STS */ | ||
"|STS", NULL))) | ||
goto pclbad; | ||
if (lastArgMatches("STS")) { | ||
i++; | ||
if (strlen(stsOutput)) { | ||
if (!getFullArg(i,cat("* Using which output mode <",stsOutput,">? ",NULL))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect indentation |
||
goto pclbad; | ||
} else { | ||
if (!getFullArg(i,"* Using which output mode <mathml>? ")) | ||
goto pclbad; | ||
} | ||
} | ||
} else { | ||
break; | ||
} | ||
|
@@ -1353,7 +1365,7 @@ flag processCommandLine(void) | |
|
||
if (cmdMatches("VERIFY")) { | ||
if (!getFullArg(1, | ||
"PROOF|MARKUP|<PROOF>")) | ||
"PROOF|MARKUP|STS|<PROOF>")) | ||
goto pclbad; | ||
if (cmdMatches("VERIFY PROOF")) { | ||
if (g_sourceHasBeenRead == 0) { | ||
|
@@ -1413,6 +1425,21 @@ flag processCommandLine(void) | |
|
||
goto pclgood; | ||
} | ||
|
||
if (cmdMatches("VERIFY STS")) { | ||
if (g_statements == 0) { | ||
print2("?No source file has been read in. Use READ first.\n"); | ||
goto pclbad; | ||
} | ||
if (strlen(stsOutput)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated code from line 586 (with i == 2) |
||
if (!getFullArg(2,cat("* Using which output mode <",stsOutput,">? ",NULL))) | ||
goto pclbad; | ||
} else { | ||
if (!getFullArg(2,"* Using which output mode <mathml>? ")) | ||
goto pclbad; | ||
} | ||
goto pclgood; | ||
} | ||
} | ||
|
||
if (cmdMatches("DBG")) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include "mmpfas.h" | ||
#include "mmunif.h" /* 26-Sep-2010 nm For g_bracketMatchInit, g_minSubstLen */ | ||
/* 1-Oct-2017 nm ...and g_firstConst */ | ||
#include "mmwsts.h" /* 27 Jul 2017 tar For MathML/STS */ | ||
|
||
/* 12-Nov-2018 nm */ | ||
/* Local prototypes */ | ||
|
@@ -352,10 +353,11 @@ void typeStatement(long showStmt, | |
} | ||
htmlDistinctVarsCommaFlag = 1; | ||
let(&str2, ""); | ||
str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt); | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str2 = stsToken(nmbrTmpPtr1[k], showStmt); | ||
else str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt); | ||
/* tokenToTex allocates str2; we must deallocate it */ | ||
let(&htmlDistinctVars, cat(htmlDistinctVars, str2, NULL)); | ||
|
||
} | ||
nmbrLet(&nmbrDDList, nmbrAddElement(nmbrDDList, nmbrTmpPtr1[k])); | ||
} | ||
|
@@ -371,7 +373,9 @@ void typeStatement(long showStmt, | |
} | ||
htmlDistinctVarsCommaFlag = 1; | ||
let(&str2, ""); | ||
str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt); | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str2 = stsToken(nmbrTmpPtr2[k], showStmt); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated code from line 357 |
||
else str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt); | ||
/* tokenToTex allocates str2; we must deallocate it */ | ||
let(&htmlDistinctVars, cat(htmlDistinctVars, str2, NULL)); | ||
|
||
|
@@ -630,11 +634,15 @@ void typeStatement(long showStmt, | |
} else { | ||
if (htmlFlg && texFlag) { | ||
let(&str2, ""); | ||
str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt); | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str2 = stsToken(nmbrTmpPtr1[k], showStmt); | ||
else str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt); | ||
/* tokenToTex allocates str2; we must deallocate it */ | ||
let(&str1, cat(str1, " ", str2, NULL)); | ||
let(&str2, ""); | ||
str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt); | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str2 = stsToken(nmbrTmpPtr2[k], showStmt); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated code from line 377 |
||
else str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt); | ||
let(&str1, cat(str1, ",", str2, NULL)); | ||
} | ||
} | ||
|
@@ -1312,7 +1320,9 @@ vstring htmlDummyVars(long showStmt) | |
/* tokenToTex allocates str1; must deallocate it first */ | ||
let(&str1, ""); | ||
/* Convert token to htmldef/althtmldef string */ | ||
str1 = tokenToTex(g_MathToken[dummyVar].tokenName, | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str1 = stsToken(dummyVar, showStmt); | ||
else str1 = tokenToTex(g_MathToken[dummyVar].tokenName, | ||
showStmt); | ||
let(&htmlDummyVarList, cat(htmlDummyVarList, " ", str1, NULL)); | ||
break; /* Found a match, so stop further checking */ | ||
|
@@ -1493,7 +1503,9 @@ vstring htmlAllowedSubst(long showStmt) | |
if (found == 0) continue; /* All set vars have $d with this wff or class */ | ||
|
||
let(&str1, ""); | ||
str1 = tokenToTex(g_MathToken[wffOrClassVar].tokenName, showStmt); | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str1 = stsToken(wffOrClassVar, showStmt); | ||
else str1 = tokenToTex(g_MathToken[wffOrClassVar].tokenName, showStmt); | ||
/* tokenToTex allocates str1; we must deallocate it eventually */ | ||
countInfo++; | ||
let(&htmlAllowedList, cat(htmlAllowedList, " ", | ||
|
@@ -1502,7 +1514,9 @@ vstring htmlAllowedSubst(long showStmt) | |
for (j = 0; j < setVars; j++) { | ||
if (setVarDVFlag[j] == 'N') { | ||
let(&str1, ""); | ||
str1 = tokenToTex(g_MathToken[setVar[j]].tokenName, showStmt); | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) str1 = stsToken(setVar[j], showStmt); | ||
else str1 = tokenToTex(g_MathToken[setVar[j]].tokenName, showStmt); | ||
let(&htmlAllowedList, cat(htmlAllowedList, | ||
(first == 0) ? "," : "", str1, NULL)); | ||
if (first == 0) countInfo++; | ||
|
@@ -2449,9 +2463,12 @@ void typeProof(long statemNum, | |
&& (!strcmp(g_Statement[stmt].labelName, "cmpt") | ||
|| !strcmp(g_Statement[stmt].labelName, "cmpt2"))) | ||
) { | ||
tmpStr1 = | ||
tokenToTex(g_MathToken[(g_Statement[stmt].mathString)[i] | ||
].tokenName, stmt); | ||
/* 27 Jul 2017 tar For MathML/STS */ | ||
if(stsFlag) tmpStr1 = | ||
stsToken((g_Statement[stmt].mathString)[i], stmt); | ||
else tmpStr1 = | ||
tokenToTex(g_MathToken[(g_Statement[stmt].mathString)[i] | ||
].tokenName, stmt); | ||
/* 14-Jan-2016 nm */ | ||
let(&tmpStr1, cat( | ||
(g_altHtmlFlag ? cat("<SPAN ", g_htmlFont, ">", NULL) : ""), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wlammen writes:
I'm not sure which info you would like to add to the README.
There is a standard .gitignore file for C projects here, we could give it a try.
Maybe better in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I added this comment is, because the metamath sources are distributed via a tar archive as well. Obviously you wont need the gitignore in this case. I think, some kind of distribution how-to is finally called for. That are my thoughts. I was curious why you added the file. Separate PR is fine with me.