https://github.com/tpapp/latexescapes.jl
Julia package for escaping strings for LaTeX and wrapping LaTeX code.
https://github.com/tpapp/latexescapes.jl
Last synced: 4 months ago
JSON representation
Julia package for escaping strings for LaTeX and wrapping LaTeX code.
- Host: GitHub
- URL: https://github.com/tpapp/latexescapes.jl
- Owner: tpapp
- License: mit
- Created: 2024-10-11T09:46:02.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-16T13:56:05.000Z (over 1 year ago)
- Last Synced: 2026-01-20T20:04:59.173Z (5 months ago)
- Language: Julia
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LaTeXEscapes.jl

[](https://github.com/tpapp/LaTeXEscapes.jl/actions/workflows/CI.yml)
[](http://codecov.io/github/tpapp/LaTeXEscapes.jl?branch=master)
[](https://github.com/JuliaTesting/Aqua.jl)
Julia package for escaping strings for LaTeX and wrapping LaTeX code.
It is intended to be used by other packages that accept strings and/or LaTeX code from the user, and output LaTeX code.
## Overview
The `LaTeX` wrapper indicates the string contained within should be treated as LaTeX code.
```julia
julia> using LaTeXEscapes
julia> l1 = lx"\copyright" # LaTeX
LaTeX(\copyright)
julia> l2 = lx"\cos(\phi)" # LaTeX wrapped in math
LaTeX(\cos(\phi))
julia> s3 = "1 < 3" # String
"1 < 3"
julia> print_escaped(stdout, l2)
\cos(\phi)
julia> print_escaped(stdout, s3)
1 \textless{} 3
```
Some rudimentary checks are performed with `print_escaped`, these can be skipped if desired.
```julia
julia> print_escaped(stdout, lx"{unbalanced")
ERROR: ArgumentError: 1 too many opening curly braces ('{')
julia> print_escaped(stdout, lx"{unbalanced"; check = false)
{unbalanced
```
Interpolation is *not supported*. Use the concatenation `*` operator:
``` julia
julia> lx"$a + " * lx"b$"
LaTeX($a + b$)
```
If the first argument is not a `LaTeX` wrapper, precede it with an empty wrapper to force escaping and conversion:
``` julia
julia> lx"" * "We are 100% sure that " * lx"$a + " * lx"b$"
LaTeX(We are 100\% sure that $a + b$)
```
## Differences from other packages
Generally, this package
1. does not make the wrapper a subtype of string, as it is *code*.
2. focuses on providing a type that users can use to signal that the input is intended to be LaTeX code.
[LaTeXStrings.jl](https://github.com/JuliaStrings/LaTeXStrings.jl) provides a similar wrapper, defaulting to math expressions. It does not handle escaping. `print_escaped` above works with the `LaTeXString` type from this package.