Browse Source

Initial push with very basic wrapper

pull/1/head
Micah Halter 1 year ago
parent
commit
03c4b84339
Signed by: mehalter GPG Key ID: 4224A6EA9A8CAAA8
  1. 21
      .github/workflows/test.yml
  2. 4
      .gitignore
  3. 20
      Project.toml
  4. 32
      README.md
  5. 24
      src/TikzCDs.jl
  6. 52
      test/runtests.jl

21
.github/workflows/test.yml

@ -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

4
.gitignore

@ -22,3 +22,7 @@ docs/site/
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml
test/*.pdf
test/*.svg
test/*.tex

20
Project.toml

@ -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"]

32
README.md

@ -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).

24
src/TikzCDs.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

52
test/runtests.jl

@ -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
Loading…
Cancel
Save