Skip to content

Commit

Permalink
Added an option to control wrapped figs
Browse files Browse the repository at this point in the history
  • Loading branch information
principejavier committed Oct 8, 2024
1 parent 206fecc commit ba84667
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/Exams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ struct WrappedFigure <: LatexFigure
vshift::Unitful.Quantity{T,Unitful.𝐋,U} where {T<:Real,U<:Unitful.Units}
lines::Integer
hang::Unitful.Quantity{T, Unitful.𝐋, U} where {T<:Real,U<:Unitful.Units}
function WrappedFigure(w,v::Quantity{T, Unitful.𝐋, U} where {T<:Real,U<:Unitful.Units};lines::Integer=-1,hang::Quantity{T, Unitful.𝐋, U} where {T<:Real,U<:Unitful.Units}=0.0cm,width_fig=w)
put_on_top::Bool
function WrappedFigure(w,v::Quantity{T, Unitful.𝐋, U} where {T<:Real,U<:Unitful.Units};lines::Integer=-1,hang::Quantity{T, Unitful.𝐋, U} where {T<:Real,U<:Unitful.Units}=0.0cm,width_fig=w,put_on_top=true)
# @assert isa(v,Unitful.Length) "vshift must be given with length units"
new(w,width_fig,v,lines,hang)
new(w,width_fig,v,lines,hang,put_on_top)
end
end
struct NoFigure<:LatexFigure end
Expand Down Expand Up @@ -616,19 +617,30 @@ function format_figure!(format::WrappedFigure,str::Vector{String})
h=format.hang
v=replace("$t",r"\s"=>"")

t=str[1]
for (i,s) in enumerate(str)
if occursin("includegraphics",s)
str[1]=replace(s,"width"=>"width=$wfig\\textwidth")
str[i]=t
break
if format.put_on_top
fig_pos = 1
t=str[fig_pos]
for (i,s) in enumerate(str)
if occursin("includegraphics",s)
str[1]=replace(s,"width"=>"width=$wfig\\textwidth")
str[i]=t
break
end
end
else
for (i,s) in enumerate(str)
if occursin("includegraphics",s)
fig_pos=i
break
end
end
end

if format.lines>0
nlines=format.lines
str[1]="\n\n\\begin{wrapfigure}[$nlines]{r}[$h]{$w\\textwidth}\n\\raggedleft\\vspace{$v}\n"*str[1]*"\\end{wrapfigure}\n\n"
str[fig_pos]="\n\n\\begin{wrapfigure}[$nlines]{r}[$h]{$w\\textwidth}\n\\raggedleft\\vspace{$v}\n"*str[1]*"\\end{wrapfigure}\n\n"
else
str[1]="\n\n\\begin{wrapfigure}{r}[$h]{$w\\textwidth}\n\\raggedleft\\vspace{$v}\n"*str[1]*"\\end{wrapfigure}\n\n"
str[fig_pos]="\n\n\\begin{wrapfigure}{r}[$h]{$w\\textwidth}\n\\raggedleft\\vspace{$v}\n"*str[1]*"\\end{wrapfigure}\n\n"
end
return "\n"
end
Expand Down

0 comments on commit ba84667

Please sign in to comment.