diff --git a/src/Microdown-LaTeXExporter-Tests/MicLaTeXWriterTest.class.st b/src/Microdown-LaTeXExporter-Tests/MicLaTeXWriterTest.class.st index 278b4d6f..f9fcb0cd 100644 --- a/src/Microdown-LaTeXExporter-Tests/MicLaTeXWriterTest.class.st +++ b/src/Microdown-LaTeXExporter-Tests/MicLaTeXWriterTest.class.st @@ -282,6 +282,37 @@ MicLaTeXWriterTest >> testLinkBold [ '\href{/anUrl}{\textbf{Foo}}', newLine ] +{ #category : 'tests - math' } +MicLaTeXWriterTest >> testMathBloc [ + + self + parseInlined:'$$ +f(a) = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z - a} dz +$$' + + andCheckWeGet: + +'\begin{equation}', newLine, +'f(a) = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z - a} dz', newLine, +'\end{equation}' +] + +{ #category : 'tests - math' } +MicLaTeXWriterTest >> testMathBlocWithLabel [ + + self + parseInlined:'$$ % label=eq1 +f(a) = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z - a} dz +$$' + + andCheckWeGet: + +'\begin{equation}', newLine, +'\label{eq1}', newLine, +'f(a) = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z - a} dz', newLine, +'\end{equation}' +] + { #category : 'tests - formats' } MicLaTeXWriterTest >> testMonospace [ @@ -417,6 +448,27 @@ MicLaTeXWriterTest >> testRealLinkSample [ '\href{http://www.pharo.org}{The Pharo Project}', newLine ] +{ #category : 'tests - math' } +MicLaTeXWriterTest >> testSimpleMathBloc [ + + | root math | + root := parser parse: ' +$$ +f(a) = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z - a} dz +$$'. + math := root children first. + self + parseInlined:'$$ +f(a) = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z - a} dz +$$' + + andCheckWeGet: + +'\begin{equation}', newLine, +'f(a) = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z - a} dz', newLine, +'\end{equation}' +] + { #category : 'tests - formats' } MicLaTeXWriterTest >> testStrike [ diff --git a/src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st b/src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st index 1b2bdd9d..216c341f 100644 --- a/src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st +++ b/src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st @@ -248,6 +248,23 @@ MicLaTeXWriter >> visitListItem: anItem [ canvas newLine ] +{ #category : 'visiting' } +MicLaTeXWriter >> visitMath: aMicMathEnvironment [ + "here we should add a label if there is one" + + canvas newLine. + canvas environment + name: 'equation'; + with: [ + | args | + args := aMicMathEnvironment arguments. + (args includesKey: 'label') + ifTrue: [ canvas raw: '\label{', (args at: 'label'), '}'. + canvas newLine.]. + + canvas raw: aMicMathEnvironment body. canvas newLine ] +] + { #category : 'blocks - inline' } MicLaTeXWriter >> visitMonospace: aMonospace [ canvas command diff --git a/src/Microdown-Tests/MicArgumentsSplitterTest.class.st b/src/Microdown-Tests/MicArgumentsSplitterTest.class.st index 9936bdd3..38b7846f 100644 --- a/src/Microdown-Tests/MicArgumentsSplitterTest.class.st +++ b/src/Microdown-Tests/MicArgumentsSplitterTest.class.st @@ -26,6 +26,19 @@ MicArgumentsSplitterTest >> testArguments [ self assert: (subject at: #foo) equals: 'bar' ] +{ #category : 'tests' } +MicArgumentsSplitterTest >> testArgumentsForMath [ + | subject | + subject := self subjectUnderTestWith: '%foo=bar'. + self assert: (subject at: #foo) equals: 'bar'. + + subject := self subjectUnderTestWith: ' %foo=bar'. + self assert: (subject at: #foo) equals: 'bar'. + + subject := self subjectUnderTestWith: ' % foo=bar'. + self assert: (subject at: #foo) equals: 'bar'. +] + { #category : 'tests' } MicArgumentsSplitterTest >> testCanInstantiate [ | subject | diff --git a/src/Microdown-Tests/MicMathBlockTest.class.st b/src/Microdown-Tests/MicMathBlockTest.class.st index 8922ca1d..8baf0796 100644 --- a/src/Microdown-Tests/MicMathBlockTest.class.st +++ b/src/Microdown-Tests/MicMathBlockTest.class.st @@ -71,6 +71,14 @@ V_i = C_0 - C_3 MicMathBlockTest >> testMathBlockWithParametersAndLatexComment [ | root math | + + "note that in the following + $$%label=eq11 + + The % is needed else it does not work on github and the label is part of the equation." + + + root := self parserClass new parse: ' ',MathOpeningBlockMarkup,'%key=cite&label=42 diff --git a/src/Microdown/MicArgumentList.class.st b/src/Microdown/MicArgumentList.class.st index e996e96d..b24b2094 100644 --- a/src/Microdown/MicArgumentList.class.st +++ b/src/Microdown/MicArgumentList.class.st @@ -75,14 +75,24 @@ MicArgumentList >> defaultValue [ { #category : 'initialization' } MicArgumentList >> from: fullString [ "I am the 'parser' of the argument splitter" - | barSplit | - fullString isEmpty ifTrue: [ ^ self ]. - (fullString intersection: '|=&') isEmpty - ifTrue: [ ^self setDefaultNoArguments: fullString ]. - barSplit := fullString splitOn: $|. + | barSplit string | + string := fullString. + string isEmpty ifTrue: [ ^ self ]. + + "for math equation we can have + $$ % label=eqq1 or + $$ %label=eqq2" + (string intersection: '%') isNotEmpty + ifTrue: [ string := string trim. + string first = $% + ifTrue: [ string := string allButFirst trim ] ]. + + (string intersection: '|=&') isEmpty + ifTrue: [ ^self setDefaultNoArguments: string ]. + barSplit := string splitOn: $|. barSplit size > 1 ifTrue: [ ^ self setDefaultAndArguments: barSplit ]. - self setNoDefaultButArguments: fullString + self setNoDefaultButArguments: string ] diff --git a/src/Microdown/MicMathBlock.class.st b/src/Microdown/MicMathBlock.class.st index 04dc34a4..1df1a63b 100644 --- a/src/Microdown/MicMathBlock.class.st +++ b/src/Microdown/MicMathBlock.class.st @@ -17,6 +17,18 @@ $$ V_i = C_0 - C_3 $$ +Now if you want to have label and references to an equation as in LaTeX you should prefix the parameter with % (else it will break on github). + + + +``` +$$ % label=theEq +V_i = C_0 - C_3 +$$ + +See *@theEq@* +``` + " Class {