mirror of https://github.com/mpastell/Weave.jl
commit
2e19930565
|
@ -309,9 +309,9 @@ export weave,
|
|||
tangle,
|
||||
convert_doc,
|
||||
notebook,
|
||||
set_chunk_defaults,
|
||||
set_chunk_defaults!,
|
||||
get_chunk_defaults,
|
||||
restore_chunk_defaults,
|
||||
restore_chunk_defaults!,
|
||||
include_weave
|
||||
|
||||
end
|
||||
|
|
|
@ -37,39 +37,31 @@ const defaultParams = Dict{Symbol,Any}(
|
|||
const rcParams = deepcopy(defaultParams)
|
||||
|
||||
"""
|
||||
set_chunk_defaults(opts::Dict{Symbol, Any})
|
||||
set_chunk_defaults!(opts::Dict{Symbol, Any})
|
||||
|
||||
Set default options for code chunks, use [`get_chunk_defaults`](@ref) to see the current values.
|
||||
|
||||
E.g.: set default `dpi` to `200` and `fig_width` to `8`
|
||||
|
||||
```julia
|
||||
julia> set_chunk_defaults(Dict{Symbol, Any}(:dpi => 200, fig_width => 8))
|
||||
julia> set_chunk_defaults!(Dict(:dpi => 200, :fig_width => 8))
|
||||
```
|
||||
"""
|
||||
function set_chunk_defaults(opts::Dict{Symbol,Any})
|
||||
merge!(rcParams[:chunk_defaults], opts)
|
||||
return nothing
|
||||
end
|
||||
set_chunk_defaults!(opts::Dict{Symbol,Any}) = merge!(rcParams[:chunk_defaults], opts)
|
||||
|
||||
"""
|
||||
get_chunk_defaults()
|
||||
|
||||
Get default options used for code chunks.
|
||||
"""
|
||||
function get_chunk_defaults()
|
||||
return (rcParams[:chunk_defaults])
|
||||
end
|
||||
get_chunk_defaults() = rcParams[:chunk_defaults]
|
||||
|
||||
"""
|
||||
restore_chunk_defaults()
|
||||
restore_chunk_defaults!()
|
||||
|
||||
Restore Weave.jl default chunk options.
|
||||
"""
|
||||
function restore_chunk_defaults()
|
||||
rcParams[:chunk_defaults] = defaultParams[:chunk_defaults]
|
||||
return nothing
|
||||
end
|
||||
restore_chunk_defaults!() = rcParams[:chunk_defaults] = defaultParams[:chunk_defaults]
|
||||
|
||||
"""Combine format specific and common options from document header"""
|
||||
function combine_args(args, doctype)
|
||||
|
|
|
@ -14,7 +14,7 @@ function WeaveDoc(source, chunks::Vector{WeaveChunk})
|
|||
|
||||
header = parse_header(first(chunks))
|
||||
# get chunk defaults from header and update
|
||||
chunk_defaults = deepcopy(rcParams[:chunk_defaults])
|
||||
chunk_defaults = deepcopy(get_chunk_defaults())
|
||||
if haskey(header, WEAVE_OPTION_NAME)
|
||||
for key in keys(chunk_defaults)
|
||||
if (val = get(header[WEAVE_OPTION_NAME], string(key), nothing)) !== nothing
|
||||
|
|
|
@ -3,7 +3,7 @@ using Test
|
|||
|
||||
# Make a dummy codehunk with figure
|
||||
chunk = Weave.CodeChunk("plot(x)", 1, 1, "", Dict())
|
||||
options = merge(Weave.rcParams[:chunk_defaults], chunk.options)
|
||||
options = merge(Weave.get_chunk_defaults(), chunk.options)
|
||||
merge!(chunk.options, options)
|
||||
chunk.figures = ["figs/figures_plot1.png"]
|
||||
|
||||
|
@ -47,4 +47,3 @@ chunk.options[:out_height] = "75 %"
|
|||
chunk.options[:out_width] = "A%"
|
||||
chunk.options[:out_height] = "0.5\\textwidth"
|
||||
@test Weave.formatfigures(chunk, Weave.tex) == "\\begin{center}\n\\includegraphics[width=A%,height=0.5\\textwidth]{figs/figures_plot1.png}\n\\end{center}\n"
|
||||
|
||||
|
|
Loading…
Reference in New Issue