Skip to content

Commit 6da4c9f

Browse files
committed
Added the ability to toggle the latex printin on and off.
1 parent cd20343 commit 6da4c9f

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ julia> P12 * [W"a" W"b" ; W`a+b` 2] == [ W"b" 2-W"b" ; W"a" W"b"]
132132
true
133133
```
134134

135+
## LateX printing in JuPyter Notebooks
136+
Printing in Juypter notebooks is by defaults done in latex.
137+
This can be turned off with the command `MathLink.set_texOutput(false)`
138+
135139
## Notes
136140

137141
- Mathematica, Wolfram, MathLink are all trademarks of Wolfram Research.

src/display.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ function Base.show(io::IO, ::MIME"image/png", w::MathLink.WExpr)
1010
end
1111

1212

13+
####If the flag for tex-output evaluation does not exist
14+
## create it and set it to true.
15+
if !@isdefined(MLtexOutput)
16+
MLtexOutput=true
17+
end
18+
19+
export set_texOutput
20+
function set_texOutput(x::Bool)
21+
global MLtexOutput
22+
MLtexOutput=x
23+
end
24+
1325
export HasGraphicsHead, HasRecursiveGraphicsHead, W2Tex
1426

1527

@@ -62,10 +74,14 @@ function HasGraphicsHead(w::MathLink.WExpr)
6274
end
6375

6476
import Base.show
77+
Base.Multimedia.showable(::MIME"text/latex", w::MathLink.WSymbol) = MLtexOutput
6578
Base.show(io,::MIME"text/latex",x::MathLink.WSymbol) = print(io,"\$"*W2Tex(x)*"\$")
6679

6780
import Base.Multimedia.showable
6881
function Base.Multimedia.showable(::MIME"text/latex", w::MathLink.WExpr)
82+
if !MLtexOutput
83+
return false
84+
end
6985
if HasRecursiveGraphicsHead(w)
7086
return false
7187
else

test/runtests.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ using Test
33

44
import MathLink: WExpr, WSymbol
55

6+
7+
68
@testset "integers" begin
79
w = W"Factorial"(30)
810
@test_throws MathLink.MathLinkError weval(Int, w)
@@ -206,19 +208,28 @@ end
206208
@test HasRecursiveGraphicsHead(weval(W`{Plot[x,{x,0,1}],Plot[x^2,{x,0,1}]}`))
207209
end
208210

211+
212+
209213
@testset "W2Tex - LaTex conversion" begin
210214
@test W2Tex(W`(a+b)^(b+x)`) == "(a+b)^{b+x}"
211215
@test W2Tex(W`a`) == "a"
212216
@test W2Tex(W`ab`) == "\\text{ab}"
213217
@test W2Tex(W`ab*cd`) == "\\text{ab} \\text{cd}"
214218

219+
215220
###Testing that MIME form exists for the text/latex option of show.
216221
io = IOBuffer();
217-
show(IOContext(io, :limit => true, :displaysize => (10, 10)),
218-
"text/plain",W"a")
222+
ioc = IOContext(io, :limit => true, :displaysize => (10, 10))
223+
show(ioc,"text/plain",W"a")
219224
@test String(take!(io)) == "W\"a\""
220-
show(IOContext(io, :limit => true, :displaysize => (10, 10)),
221-
"text/plain",W"a"+W"b")
225+
show(ioc,"text/plain",W"a"+W"b")
222226
@test String(take!(io)) == "W\"Plus\"(W\"a\", W\"b\")"
227+
228+
set_texOutput(true)
229+
show(ioc,"text/latex",W"a"+W"b")
230+
@test String(take!(io)) == "\$a+b\$"
231+
@test showable("text/latex",W"a"+W"b")
232+
set_texOutput(false)
233+
@test !showable("text/latex",W"a"+W"b")
223234
end
224235

0 commit comments

Comments
 (0)