Top Banner
Wikipedia: Improving the rendering of chemical formulae Student: Manfred Schäfer Supervisor: Moritz Schubotz Examiner: Prof. Dr. Bela Gipp Date: 2017-07-17
14

Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

May 23, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Wikipedia:Improvingtherenderingof

chemicalformulae

Student:ManfredSchäferSupervisor:MoritzSchubotzExaminer:Prof.Dr.BelaGippDate:2017-07-17

Page 2: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

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

Page 3: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

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

Page 4: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Whyusetexvcjs atall?• Security:texvcjs ensuresthatonly“safe”LaTeXexpressionsareusedandattackmethodslikecrosssitescriptingareprevented• ReplacesMediaWiki specificfunctions• MakesLaTeX expressionsmoreconsistentbyintroducingbracesorremovingwhitespacesbeforerendering

2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 4

Page 5: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

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

Page 6: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Researchtasks– Milestones• Familiarizemyselfwiththestructureoftherenderingpipeline• Evaluatethefouroptionsandchoseone:option(1)waschosen• Implementoption(1)• Developtestcasesandtestthesystem

2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 6

Page 7: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Challenges• Understandingpegjs• Understandinghowtheabstractsyntaxtreeisbuilt• Grammarcontainsleftrecursion• Switchingbacktomathmodewith'$'

2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 7

Page 8: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

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

Page 9: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Testing• TestcasesforthenewfunctionalityAllexamplesofthemhchemmanualkeeptheirspacing• Coveragetesting100%codecoverageisdesired,currently76%oflinesarecovered• RegressiontestingThenewcodeshouldproducethesameoutputliketheoldcodeformathematicalformulae

2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 9

Page 10: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

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

Page 11: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Outlook– Nextsteps• Finalizecode,colormodifierswithinchemicalformulaemightstillneedsomework• Improvecodecoveragebyaddingmoretestcases• Codereviewbyotherdevelopers• Mergeintotheupstreamcode• Productionuseofthenewcode

2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 11

Page 12: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Conclusion• Grammarofmhchem isimplemented• Testsforchemicalformulaeexists• Itlookslikethenewcodehasn’tbrokenanythingelse

2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 12

Page 13: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

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

Page 14: Wikipedia: Improving the rendering of chemical formulae · Outlook –Next steps •Finalize code, color modifiers within chemical formulae might still need some work •Improve code

Questions?

2017-07-17 Schäfer,Manfred– Improvingtherenderingofchemicalformulae 14