Skip to content

replace all latex escape characters #81

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions ext/TikzGraphsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ import CausalInference

CausalInference.EXTENSIONS_SUPPORTED ? (using TikzGraphs) : (using ..TikzGraphs)

"""Reformat an input string to escape characters reserved for latex"""
function escape_latex_characters(input_string::String)

simple_replacements = replace(input_string, r"([{}&#_%]{1})"=>s"\\\1")
caret = replace(simple_replacements, r"\^"=>s"\\^{}")
dollar = replace(caret, r"\$"=>s"\\$")
backslash = replace(dollar, r"\\(?![$%^&{}_#])"=>s"")
return backslash
end

function CausalInference.plot_pc_graph_tikz(g,
node_labels::AbstractVector{<:AbstractString} = String[])
objs = CausalInference.prepare_pc_graph(g, node_labels)
TikzGraphs.plot(objs.plot_g, [replace(label, "_"=>" ") for label in objs.node_labels],
TikzGraphs.plot(objs.plot_g,
[escape_latex_characters(label) for label in objs.node_labels],
edge_styles = objs.edge_styles, node_style = objs.node_style,
options = objs.options)
end

function CausalInference.plot_fci_graph_tikz(g,
node_labels::AbstractVector{<:AbstractString} = String[])
objs = CausalInference.prepare_fci_graph(g, node_labels)
TikzGraphs.plot(objs.plot_g, [replace(label, "_"=>" ") for label in objs.node_labels],
TikzGraphs.plot(objs.plot_g,
[escape_latex_characters(label) for label in objs.node_labels],
edge_styles = objs.edge_styles, node_style = objs.node_style,
options = objs.options)
end
Expand Down