Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d260f72
›Add refactor prototype.
korsbo Jan 29, 2021
f39f275
Revise refactor prototype.
korsbo Jan 30, 2021
e6238f3
Add trig and assignment prototypes.
korsbo Jan 30, 2021
24c7440
Rearrange refactor prototype.
korsbo Jan 30, 2021
168fd2e
Add meta customisation to refactor prototype.
korsbo Jan 31, 2021
f756525
Update refactor protoypte.
korsbo Feb 16, 2021
6f45c4f
Add function-list refactor prototype.
korsbo Feb 16, 2021
c20820b
Revise refactor prototype 2.
korsbo Feb 23, 2021
54dde4f
Move refactor prototype into src
korsbo Feb 28, 2021
ae1a6fa
Add renrer `\usepackage`.
korsbo Feb 28, 2021
a64c351
Integrate and update refactor prototype.
korsbo Apr 6, 2021
4acc683
Stop recusing to top-level call. Breaks recipes.
korsbo Apr 7, 2021
137dcb8
Enable rendering via a kwargs.
korsbo Apr 7, 2021
473032a
Add non-nested types to `decend`.
korsbo Apr 7, 2021
ba94fc9
Implement all operations in refactor.
korsbo Apr 9, 2021
d8a5742
Fix kwarg treatment when latexifying functions.
korsbo Apr 9, 2021
3ad951d
Integrate refactor prototype into src properly.
korsbo Apr 9, 2021
7255375
Add type annotation support.
korsbo Apr 9, 2021
9f1a3f9
Fix and update tests. Recipes still broken.
korsbo Apr 9, 2021
9ae35a6
remove broken latexoperation import
korsbo Apr 9, 2021
068a37e
Stop testing on Julia 0.7.
korsbo Apr 9, 2021
4a5c03e
Test older Julia versions too.
korsbo Apr 9, 2021
da056d6
Remove old refactor prototypes.
korsbo Apr 10, 2021
1d86347
Fix LaTeXString substring passthrough.
korsbo Apr 10, 2021
267308c
Replace latexify top function.
korsbo Apr 11, 2021
056ba0c
Stop recursing to top-level function.
korsbo Apr 12, 2021
d59f5b5
Add IOStream prototype.
korsbo Apr 12, 2021
e870cd2
Reinstate recipes.
korsbo Apr 12, 2021
7c5f972
WIP: play with recipes in recipes test.
korsbo Apr 12, 2021
b208c68
Way too much stuff for a commit.
korsbo Apr 16, 2021
e1348da
Fix broken env inference.
korsbo Apr 16, 2021
86d1ee3
Propagate `rules` along `descend`.
korsbo Dec 13, 2021
d9d3b89
Add `TracedIO` for better testing.
korsbo Dec 13, 2021
e6d3310
Greatly improve parity with main.
korsbo Sep 5, 2022
7ee625f
Fix some tests
korsbo Sep 6, 2022
7b3299d
Mark DataFrames and MDTable tests broken.
korsbo Sep 6, 2022
ce78c3e
Purge some deprecated code.
korsbo Sep 6, 2022
2f285ff
Rename file with latexification instructions.
korsbo Sep 6, 2022
e68b147
Support latexifying macros in exprs.
korsbo Sep 13, 2022
29a6711
Add broken test
korsbo Sep 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
version:
- '0.7'
- '0.7'
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
- 'nightly'
os:
Expand Down
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
Formatting = "0.4"
LaTeXStrings = "0.3, 1"
MacroTools = "0.4, 0.5"
Requires = "0.5, 1"
julia = "1"

[extras]
Expand Down
84 changes: 53 additions & 31 deletions src/Latexify.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Latexify
using Requires
# Base.Experimental.@compiler_options optimize=0 compile=min infer=no
# using Requires
using LaTeXStrings
using InteractiveUtils
using Markdown
Expand All @@ -8,63 +9,44 @@ import MacroTools
using Printf
using Formatting

export latexify, md, copy_to_clipboard, auto_display, set_default, get_default,
export latexify, copy_to_clipboard, auto_display, set_default, get_default,
reset_default, @latexrecipe, render, @latexify, @latexrun

## Allow some backwards compatibility until its time to deprecate.
export latexequation, latexarray, latexalign, latexraw, latexinline, latextabular, mdtable

export StyledNumberFormatter, FancyNumberFormatter

COPY_TO_CLIPBOARD = false
const COPY_TO_CLIPBOARD = false
function copy_to_clipboard(x::Bool)
global COPY_TO_CLIPBOARD = x
end

AUTO_DISPLAY = false
const AUTO_DISPLAY = false
function auto_display(x::Bool)
global AUTO_DISPLAY = x
end

include("unicode2latex.jl")
include("function2latex.jl")
include("latexraw.jl")
include("latexoperation.jl")
include("latexarray.jl")
include("latexalign.jl")
include("latexbracket.jl")
include("latexinline.jl")
include("latexequation.jl")
include("latextabular.jl")
include("default_kwargs.jl")
include("recipes.jl")
include("macros.jl")
include("instructions.jl")

include("mdtable.jl")
include("mdtext.jl")
include("md.jl")
# include("mdtable.jl")
# include("mdtext.jl")
# include("md.jl")

include("utils.jl")
include("TracedIO.jl")
include("config.jl")

include("numberformatters.jl")

include("latexify_function.jl")
# include("refactor_prototype_2.jl")
export descend, unpack, head, operation, arguments, nested

### Add support for additional packages without adding them as dependencies.
function __init__()
@require DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" begin
include("plugins/ParameterizedFunctions.jl")
end
@require DiffEqBiological = "eb300fae-53e8-50a0-950c-e21f52c2b7e0" begin
include("plugins/DiffEqBiological.jl")
end
@require SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8" begin
include("plugins/SymEngine.jl")
end
@require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" begin
include("plugins/DataFrames.jl")
end
end

macro generate_test(expr)
return :(clipboard("@test $($(string(expr))) == replace(\nraw\"$($(esc(expr)))\", \"\\r\\n\"=>\"\\n\")\n"))
Expand Down Expand Up @@ -125,4 +107,44 @@ macro append_test!(fname, str)
)
end

# const _ex = :(a+w*c/d-b+1+1. + [1,x/y^2] * [1 2. 2im] .* x ± x = l_Huge(y))
# latexify(:(a+w*c/d-b+1+1. + [1,x/y^2] * [1 2. 2im] .* x ± x = l_Huge(y)))
# Latexify._latextree(:(a+w*c/d-b+1+1. + [1,x/y^2] * [1 2. 2im] .* x ± x = l_Huge(y)))
# latexify(:(a+w*c/d-b+1+1. + [1,x/y^2] * [1 2. 2im] .* x ± x = l_Huge(y)))
# latexify(:(a+w*c/d-b+1+1. + [1,x/y^2] * [1 2. 2im] .* x ± x = l_Huge(y)))
# latexify(_ex)
# latexify(_ex)
# @assert precompile(latexify, (Expr,))

latexify(:(z/y*s+1.2+1//2))
for f in DEFAULT_INSTRUCTIONS
for op in [Expr, Symbol, Float64, Int, Rational, ComplexF64]
for config in [Dict, NamedTuple]
for prevop in [Symbol, Nothing]
precompile(f, (IOBuffer, config, op, prevop ))
end
end
end
end


# ### Add support for additional packages without adding them as dependencies.
# function __init__()
# @require DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" begin
# include("plugins/ParameterizedFunctions.jl")
# end
# @require DiffEqBiological = "eb300fae-53e8-50a0-950c-e21f52c2b7e0" begin
# include("plugins/DiffEqBiological.jl")
# end
# @require SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8" begin
# include("plugins/SymEngine.jl")
# end
# @require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" begin
# include("plugins/DataFrames.jl")
# end
# # Latexify._latextree(:(a+w*c/d-b+1+1. + [1,x/y^2] * [1 2. 2im] .* x ± x = l_Huge(y)))
# # Latexify.latexify(:(a+w*c/d-b+1+1. + [1,x/y^2] * [1 2. 2im] .* x ± x = l_Huge(y)))
# end

end

19 changes: 19 additions & 0 deletions src/TracedIO.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

struct TracedIO{T} <: IO
trace::Vector{Function}
io::T
end
Base.write(x::TracedIO, s::String; kwargs...) = Base.write(x.io, s; kwargs...)

struct TracedResult{T}
trace::Vector{Function}
str::T
end

function Base.show(io::IO, tio::TracedResult)
write(io, "Latexify TracedResult\n")
write(io, "\nwith call trace:\n")
write(io, join(string.(typeof.(tio.trace)), "\n"))
write(io, "\n\nand result\n")
show(io, tio.str)
end
35 changes: 35 additions & 0 deletions src/config.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const DEFAULT_CONFIG = (;
:mulsym => " \\cdot ",
:convert_unicode => true,
:strip_broadcast => true,
:fmt => identity,
:index => :bracket,
:ifstr => "\\text{if }",
:elseifstr => "\\text{elseif }",
:elsestr => "\\text{otherwise}",
:adjustment => "c",
:transpose => false,
:double_linebreak => false,
:starred => false,
)

## MODULE_CONFIG can store defaults specified in other modules. E.g. from recipes.
const MODULE_CONFIG = Dict{Symbol, Any}()

## USE_CONFIG can store user-specified defaults
const USER_CONFIG = Dict{Symbol, Any}()

const comparison_operators = (;
:< => "<",
:.< => "<",
:> => ">",
:.> => ">",
Symbol("==") => "=",
Symbol(".==") => "=",
:<= => "\\leq",
:.<= => "\\leq",
:>= => "\\geq",
:.>= => "\\geq",
:!= => "\\neq",
:.!= => "\\neq",
)
Loading