Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code,...
Transcript of Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code,...
Wikipedia:Improvingtherenderingof
chemicalformulae
Student:ManfredSchäferSupervisor:MoritzSchubotzExaminer:Prof.Dr.BelaGippDate:2017-07-17
Motivation
H2O<chem>H2O</chem>
(NH4)2S<chem>(NH4)2S</chem>
2Na+2H2O⟶ 2Na+ +OH– +H–H<chem>2Na + 2H2O -> 2Na+ + 2OH- + H-H</chem>
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 2
Motivation
\ce{2Na + 2H2O -> 2Na+ + 2OH- + H-H}
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 3
2 Na + 2 H2O ��! 2 Na+ + 2 OH– + H–H
Whyusetexvcjs atall?• Security:texvcjs ensuresthatonly“safe”LaTeXexpressionsareusedandattackmethodslikecrosssitescriptingareprevented• ReplacesMediaWiki specificfunctions• MakesLaTeX expressionsmoreconsistentbyintroducingbracesorremovingwhitespacesbeforerendering
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 4
Objective• Adjusttexvcjs topreventwhitespacemodificationsince-tags• Discussedoptionswere:
(1) Developafullgrammarformhchem(2) Extendgrammaroftexvcjs totreat\ce like
\mbox(3) Bypasstexvcjs altogetherforrendering(4) Duplicatemhchem parserintotexvcjs
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 5
Researchtasks– Milestones• Familiarizemyselfwiththestructureoftherenderingpipeline• Evaluatethefouroptionsandchoseone:option(1)waschosen• Implementoption(1)• Developtestcasesandtestthesystem
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 6
Challenges• Understandingpegjs• Understandinghowtheabstractsyntaxtreeisbuilt• Grammarcontainsleftrecursion• Switchingbacktomathmodewith'$'
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 7
mhchem Grammar<ce> ::= <sentence> <sentence> ::= <phrase>
| <sentence> Space <phrase> <phrase> ::= <word>
| <word> <single macro> | <single macro> | '^' | '(^)'
<word> ::= <nonletter> | Letter | <single macro> <nonletter> | <word> <nonletter> | <word> Letter | <word> <single macro> <nonletter>
<nonletter> ::= '$' <LaTeX expression> '$'| ...
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 8
Testing• TestcasesforthenewfunctionalityAllexamplesofthemhchemmanualkeeptheirspacing• Coveragetesting100%codecoverageisdesired,currently76%oflinesarecovered• RegressiontestingThenewcodeshouldproducethesameoutputliketheoldcodeformathematicalformulae
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 9
Example• Input\ce{2Na + 2H2O -> 2Na+ + 2OH- + H-H}
• Outputbeforetheproject{\ce {2Na+2H2O->2Na++2OH-+H-H}}
• Outputnow{\ce {2Na + 2H2O -> 2Na+ + 2OH- + H-H}}
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 10
Outlook– Nextsteps• Finalizecode,colormodifierswithinchemicalformulaemightstillneedsomework• Improvecodecoveragebyaddingmoretestcases• Codereviewbyotherdevelopers• Mergeintotheupstreamcode• Productionuseofthenewcode
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 11
Conclusion• Grammarofmhchem isimplemented• Testsforchemicalformulaeexists• Itlookslikethenewcodehasn’tbrokenanythingelse
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 12
References• [1]MartinHensel:Themhchem Bundle,
DocumentationfortheLaTeX Packagesmhchemv4.04,hpstatement v1.02andrsphrase v3.11.2016
• [2]⚓ T140217Adjusttexvcjs topreventwhitespacemodificationsince-tags,2016.RetrievedMay14,2017fromPhabricator,wikimedia:phabricator.wikimedia.org/T140217
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 13
Questions?
2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 14