@ -0,0 +1,21 @@ | |||
name: Tests | |||
on: [push, pull_request] | |||
jobs: | |||
test: | |||
runs-on: ${{ matrix.os }} | |||
strategy: | |||
fail-fast: false | |||
matrix: | |||
julia-version: ['1.0', '1.4', '1.5'] | |||
os: [ubuntu-latest] | |||
steps: | |||
- uses: actions/checkout@v2 | |||
- name: "Set up Julia" | |||
uses: julia-actions/setup-julia@latest | |||
with: | |||
version: ${{ matrix.julia-version }} | |||
- name: "Run tests" | |||
uses: julia-actions/julia-runtest@master |
@ -0,0 +1,20 @@ | |||
name = "TikzCDs" | |||
uuid = "1e332c56-9431-4126-8a34-92cbdf251ae4" | |||
license = "MIT" | |||
authors = ["Micah Halter <micah@mehalter.com>"] | |||
version = "0.1.0" | |||
[deps] | |||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" | |||
TikzPictures = "37f6aa50-8035-52d0-81c2-5a1d08754b2d" | |||
[compat] | |||
LaTeXStrings = "^1.1" | |||
TikzPictures = "^3.3" | |||
julia = "1" | |||
[extras] | |||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | |||
[targets] | |||
test = ["Test"] |
@ -1,2 +1,32 @@ | |||
# TikzCD.jl | |||
Draw commutative diagrams using tikz-cd | |||
A wrapper around [TikzPictures.jl](https://github.com/JuliaTeX/TikzPictures.jl) | |||
for easier drawing of commutative diagrams using | |||
[`tikz-cd`](https://www.ctan.org/pkg/tikz-cd) | |||
### Dependencies | |||
*Currently requires `TikzPictures.jl` to be added in development using `]dev | |||
TikzPictures`* | |||
In order to use this library, `lualatex` must be installed. | |||
The `texlive` and `miktex` distributions include `lualatex`. | |||
You must also have `dvisvgm` installed. | |||
On Ubuntu, you can get these, if not already present, by running: | |||
``` | |||
sudo apt-get install texlive-latex-base and sudo apt-get install texlive-binaries | |||
``` | |||
## Example | |||
```julia | |||
tp = TikzCD(L""" | |||
A \arrow{rd} \arrow{r} & B \\ | |||
& C | |||
""", options="scale=0.25") | |||
``` | |||
For more usage details, check out the | |||
[TikzPictures.jl repository](https://github.com/JuliaTeX/TikzPictures.jl). |
@ -0,0 +1,24 @@ | |||
module TikzCDs | |||
using TikzPictures | |||
import TikzPictures: PDF, TEX, TIKZ, SVG, save, TikzDocument, push!, tikzCommand | |||
export PDF, TEX, TIKZ, SVG, save, TikzDocument, push!, tikzCommand | |||
import LaTeXStrings: LaTeXString, @L_str, @L_mstr | |||
export LaTeXString, @L_str, @L_mstr | |||
export TikzCD | |||
function TikzCD(data::AbstractString; options="", preamble="", enableWrite18=true) | |||
# check for tikz-cd package being imported | |||
if !occursin("\\usepackage{tikz-cd}", preamble) | |||
preamble = strip(string("\\usepackage{tikz-cd}\n", preamble)) | |||
end | |||
# tikz-cd doesn't support the content being in a $$, so this helps when using LaTeXStrings | |||
if typeof(data) == LaTeXString | |||
data = strip(data[2:end-1]) | |||
end | |||
TikzPicture(data, options=options, preamble=preamble, environment="tikzcd", enableWrite18=enableWrite18) | |||
end | |||
end |
@ -0,0 +1,52 @@ | |||
# BASED ON TIKZPICTURES.JL TESTS | |||
using TikzCDs | |||
using Test | |||
for file in ["testCD.pdf", "testCDDoc.pdf", "testCD.tex"] | |||
if isfile(file) | |||
rm(file) | |||
end | |||
end | |||
# check that the TEX file contains the desired environments | |||
function has_environment(content::String, environment::String) | |||
has_begin = occursin("\\begin{$environment}", content) | |||
has_end = occursin("\\end{$environment}", content) | |||
if has_begin && has_end | |||
return true # has both | |||
elseif !has_begin && !has_end | |||
return false # has neither | |||
else | |||
error("\\begin{$environment} and \\end{$environment} do not match") | |||
end | |||
end | |||
# Test tikz-cd | |||
data = L""" | |||
A \arrow{rd} \arrow{r} & B \\ | |||
& C | |||
""" | |||
tp = TikzCD(data, options="scale=0.25") | |||
td = TikzDocument() | |||
push!(td, tp, caption="hello") | |||
save(TEX("testCD"), tp) | |||
@test isfile("testCD.tex") | |||
filecontent = join(readlines("testCD.tex", keep=true)) # read with line breaks | |||
@test occursin(strip(data[2:end-1]), filecontent) # also check that the data is contained | |||
@test has_environment(filecontent, "tikzcd") | |||
@test has_environment(filecontent, "document") | |||
if success(`lualatex -v`) | |||
save(PDF("testCD"), tp) | |||
@test isfile("testCD.pdf") | |||
save(PDF("testCDDoc"), td) | |||
@test isfile("testCDDoc.pdf") | |||
else | |||
@warn "lualatex is missing; can not test compilation" | |||
end |