Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add post-processing hook. #83

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions src/latexalign.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ julia> latexalign(ode)
"""
function latexalign end

function latexalign(arr::AbstractMatrix; separator=" =& ", double_linebreak=false, starred=false, kwargs...)
function latexalign(arr::AbstractMatrix; separator=" =& ", double_linebreak=false, eol = double_linebreak ? " \\\\\\\\\n" : " \\\\\n", starred=false, kwargs...)
(rows, columns) = size(arr)
eol = double_linebreak ? " \\\\\\\\\n" : " \\\\\n"
arr = latexraw(arr; kwargs...)

str = "\\begin{align$(starred ? "*" : "")}\n"
Expand All @@ -52,9 +51,9 @@ function latexalign(arr::AbstractMatrix; separator=" =& ", double_linebreak=fals
end
str *= join(arr[end,:], separator) * "\n" # No EOL on the last line.
str *= "\\end{align$(starred ? "*" : "")}\n"
latexstr = LaTeXString(str)
COPY_TO_CLIPBOARD && clipboard(latexstr)
return latexstr
#= latexstr = LaTeXString(str) =#
#= COPY_TO_CLIPBOARD && clipboard(latexstr) =#
return output(str; kwargs...)
end

function latexalign(lhs::AbstractArray, rhs::AbstractArray; kwargs...)
Expand Down
4 changes: 1 addition & 3 deletions src/latexarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ function latexarray(arr::AbstractArray; adjustment::Symbol=:c, transpose=false,
str *= "\\end{array}\n"
str *= "\\right]\n"
str *= "\\end{equation$(starred ? "*" : "")}\n"
latexstr = LaTeXString(str)
COPY_TO_CLIPBOARD && clipboard(latexstr)
return latexstr
return output(str; kwargs...)
end


Expand Down
4 changes: 1 addition & 3 deletions src/latexequation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ function latexequation(eq; starred=false, kwargs...)
str *= latexstr
str *= "\n"
str *= "\\end{equation$(starred ? "*" : "")}\n"
latexstr = LaTeXString(str)
COPY_TO_CLIPBOARD && clipboard(latexstr)
return latexstr
return output(str; kwargs...)
end

10 changes: 10 additions & 0 deletions src/latexify_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ function get_latex_function(x::AbstractArray{T}) where T <: AbstractArray
end

get_latex_function(lhs::AbstractVector, rhs::AbstractVector) = latexalign


function output(str; post_processing=x->x, escape_underscores=false, kwargs...)
str = post_processing(str)
str == nothing && return nothing
escape_underscores && (str = replace(str, "_"=>"\\_"))
latexstr = LaTeXString(str)
COPY_TO_CLIPBOARD && clipboard(latexstr)
return latexstr
end
3 changes: 1 addition & 2 deletions src/latexinline.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function latexinline(x; kwargs...)
latexstr = latexstring( latexraw(x; kwargs...) )
COPY_TO_CLIPBOARD && clipboard(latexstr)
return latexstr
return output(latexstr.s; kwargs...)
end

latexinline(x::Union{AbstractArray, Tuple}; kwargs...) = [ latexinline(i; kwargs...) for i in x]
Expand Down
4 changes: 1 addition & 3 deletions src/latextabular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ function latextabular(arr::AbstractMatrix; latex::Bool=true, head=[], side=[], a
end

str *= "\\end{tabular}\n"
latexstr = LaTeXString(str)
COPY_TO_CLIPBOARD && clipboard(latexstr)
return latexstr
return output(str; kwargs...)
end


Expand Down
4 changes: 1 addition & 3 deletions src/plugins/DiffEqBiological.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ function chemical_arrows(rn::DiffEqBase.AbstractReactionNetwork;

str *= starred ? "\\end{align*}\n" : "\\end{align}\n"

latexstr = LaTeXString(str)
COPY_TO_CLIPBOARD && clipboard(latexstr)
return latexstr
return output(str; kwargs...)
end


Expand Down