Skip to content

Commit

Permalink
fix tikz demo (#1021)
Browse files Browse the repository at this point in the history
* fix tikz demo

* skip tikz demo on apple ARM

* define tikzcd env as empty on apple arm
  • Loading branch information
fkastner authored Apr 28, 2023
1 parent c5e0246 commit 41369d8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions demos/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
TikzPictures = "37f6aa50-8035-52d0-81c2-5a1d08754b2d"
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
Weave = "44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9"
3 changes: 2 additions & 1 deletion demos/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ maxtoclevel = 3
mathjax = false
ignore = ["foo/content.md"]
weave = false

generate_sitemap = true

isAppleARM = Sys.isapple() && Sys.ARCH === :aarch64

# supports question 001
members_from_csv = eachrow(readdlm("_assets/members.csv", ',', skipstart=1))
+++
Expand Down
13 changes: 5 additions & 8 deletions demos/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,12 @@ and that's it 🏁.
## (009) custom environment for TikzCD
> TikzCDs is currently too disfunctional so the demo is commented out for now. Like TikzPicture, it's possible to make it work with Tectonic but Tectonic doesn't work on M* macs.
{{if isAppleARM}}
> This demo unfortunately doesn't work on Apple ARM since it uses tectonic through the [TikzPictures.jl](https://github.com/JuliaTeX/TikzPictures.jl) package. See issue [Tectonic.jl#13](https://github.com/MichaelHatherly/Tectonic.jl/issues/13).
<!--
{{else}}
Following up on [#008](#008_custom_environments_and_commands), here's a custom environment for Tikz diagrams using the [TikzCDs.jl](https://github.com/JuliaTeX/TikzCDs.jl) package.
Following up on [#008](#008_custom_environments_and_commands), here's a custom environment for Tikz diagrams using the [TikzPictures.jl](https://github.com/JuliaTeX/TikzPictures.jl) package.
Let's first see what you get for your effort:
Expand All @@ -279,11 +280,7 @@ A \arrow[r, "\phi"] \arrow[d, red]
The corresponding `env_tikzcd` function is in the `utils.jl` file and is quite simple.
**Note**: in this particular case, the environment uses the [`TikzCDs.jl`](https://github.com/JuliaTeX/TikzCDs.jl) which requires having `lualatex` and `dvisgm` as per their README.
For this to work with a GitHub action, the relevant stuff needs to be installed, it's not hard to do so with GitHub actions though you need to get TeXLive 2019 to avoid errors, I used [these 3 lines](https://github.com/tlienart/Franklin.jl/blob/354ac015c14aaedf9ebeaeb9d0b574ddad3738e5/.github/workflows/deploy.yml#L20-L23) which you could copy.
-->
{{end}}
## (008) (custom) environments and commands
Expand Down
43 changes: 27 additions & 16 deletions demos/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
# Project.toml and the `deploy.yml` file here as examples.
#
using DelimitedFiles
# using TikzCDs
using Dates
using Weave
using DataFrames
using PrettyTables

const isAppleARM = Sys.isapple() && Sys.ARCH === :aarch64
if !isAppleARM
using TikzPictures
end

# ========================================================================

###########
Expand Down Expand Up @@ -73,21 +77,28 @@ end
### 009 ###
###########

# XXX TikzCD is too disfunctional as of April 2023

# function env_tikzcd(e, _)
# content = strip(Franklin.content(e))
# name = strip(Franklin.content(e.braces[1]))
# # save SVG at __site/assets/[path/to/file]/$name.svg
# rpath = joinpath("assets", splitext(Franklin.locvar(:fd_rpath))[1], "$name.svg")
# outpath = joinpath(Franklin.path(:site), rpath)
# # if the directory doesn't exist, create it
# outdir = dirname(outpath)
# isdir(outdir) || mkpath(outdir)
# # save the file and show it
# save(SVG(outpath), TikzCD(content))
# return "\\fig{/$(Franklin.unixify(rpath))}"
# end
if !isAppleARM

# so we don't have to install LaTeX on CI
tikzUseTectonic(true)

function env_tikzcd(e, _)
content = strip(Franklin.content(e))
name = strip(Franklin.content(e.braces[1]))
# save SVG at __site/assets/[path/to/file]/$name.svg
rpath = joinpath("assets", splitext(Franklin.locvar(:fd_rpath))[1], "$name.svg")
outpath = joinpath(Franklin.path(:site), rpath)
# if the directory doesn't exist, create it
outdir = dirname(outpath)
isdir(outdir) || mkpath(outdir)
# save the file and show it
save(SVG(outpath), TikzPicture(content; environment="tikzcd", preamble="\\usepackage{tikz-cd}"))
return "\\fig{/$(Franklin.unixify(rpath))}"
end

else
env_tikzcd(_, _) = ""
end

###########
### 013 ###
Expand Down

0 comments on commit 41369d8

Please sign in to comment.