Skip to content

Commit

Permalink
Several minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
principejavier committed May 28, 2024
1 parent c41bf11 commit a6c6b23
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 73 deletions.
36 changes: 6 additions & 30 deletions src/Exams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,6 @@ const MoodleTemplate="""
\\documentclass[11pt]{article}
\\usepackage{amssymb,amsmath}
\\usepackage{moodle}
% Fix from https://tex.stackexchange.com/questions/545421/moodle-sty-does-not-include-multiple-quiz
\\makeatletter
\\def\\openmoodleout{%
\\immediate\\openout\\moodle@outfile=\\outputfilename\\relax
\\writetomoodle{<?xml version="1.0" encoding="UTF-8"?>}%
\\writetomoodle{<quiz>}%
\\writetomoodle{ }%
}%
\\renewenvironment{quiz}[2][]%
{
\\setkeys{moodle}{#1}%
\\@moodle@ifgeneratexml{\\setcategory{#2}}{}%
\\subsection*{#2}%
\\begin{enumerate}%
}{
\\end{enumerate}%
}
\\AfterEndPreamble{
\\@moodle@ifgeneratexml{\\openmoodleout}{}%
}
\\AtEndDocument{
\\@moodle@ifgeneratexml{\\closemoodleout}{}%
}
\\makeatother
\\usepackage[{{{Language}}}]{babel} % hyphentation
\\usepackage{graphics}
\\usepackage{pgf}
Expand Down Expand Up @@ -188,7 +164,7 @@ StandardHeadings[SPA]=Dict{String,String}()
StandardHeadings[CAT]=Dict{String,String}()
StandardHeadings[ENG]=Dict{String,String}()

StandardHeadings[SPA]["Language"]=SPA
StandardHeadings[SPA]["Language"]=SPA*",es-nodecimaldot"
StandardHeadings[CAT]["Language"]=CAT
StandardHeadings[ENG]["Language"]=ENG

Expand Down Expand Up @@ -834,11 +810,11 @@ function question(format::PrintedQuestion, msg, var, unitname=""; factor1=rand2(
pos = format.right[format.int_params[2]][format.int_params[1]]
res = Array{String}(undef,5);

res[mod(pos, 5) + 1] = val2latex(val1)
res[mod(pos + 1, 5) + 1] = val2latex(val2)
res[mod(pos + 2, 5) + 1] = val2latex(val3)
res[mod(pos + 3, 5) + 1] = val2latex(val4)
res[mod(pos + 4, 5) + 1] = val2latex(val)
res[mod(pos, 5) + 1] = "\$"*val2latex(val1)*"\$"
res[mod(pos + 1, 5) + 1] = "\$"*val2latex(val2)*"\$"
res[mod(pos + 2, 5) + 1] = "\$"*val2latex(val3)*"\$"
res[mod(pos + 3, 5) + 1] = "\$"*val2latex(val4)*"\$"
res[mod(pos + 4, 5) + 1] = "\$"*val2latex(val)*"\$"

str=print_answers(format.width[num_question],format.num_rows[num_question],num_question,msg,res)
return str
Expand Down
2 changes: 1 addition & 1 deletion test/example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function generate_exam(nump)
headings[ENG]["GraphicsPath"] = "{../assets/}"

#exam = PrintedExam(nump,languages=[SPA],headings=headings)
exam = PrintedExam(nump,languages=[SPA],headings=headings,name="PrintedExamTest",format=PrintedQuestion([1,2,1,1,1,2,5],[2cm,2cm,2cm,2cm,2cm,2.5cm,15cm]))
exam = PrintedExam(nump,languages=[SPA,CAT],headings=headings,name="PrintedExamTest",format=PrintedQuestion([1,2,1,1,1,2,5],[2cm,2cm,2cm,2cm,2cm,2.5cm,15cm]))

mass=[1kg,2kg];
h0=[1m,2m];
Expand Down
91 changes: 52 additions & 39 deletions test/problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ function free_fall(mass,h0,v0,language=nothing,format=nothing)

mass_out=var2out(mass)
h0_out=var2out(h0)
v0_out=var2out(v0)
v0_out=var2out(v0,"","m/s")
g=9.81m/s^2
g_out=var2out(g,"","m/s^2")

#h=h0+v0*t-0.5*g*t^2
t=2*v0/g+sqrt(v0^2+2*g*h0)/g
v=v0-g*t

problem=Vector{String}(undef,0)
if language==SPA
statement = "Un cuerpo de masa $mass_out es lanzado hacia arriba desde una altura $h0_out a una velocidad $v0_out como se muestra en la figura~\\ref{fig:caidalibre}. La aceleración local de la gravedad es $g_out. Determinar:"
figure1 = figure("ball","fig:caidalibre","Cuerpo en caída libre");
question1 = question(format,"el tiempo que tarda en caer al suelo (en unitname),", t,"s");
question2 = question(format,"la velocidad que alcanza al tocar el suelo (en unitname),", v,"km/h");
push!(problem,"Un cuerpo de masa $mass_out es lanzado hacia arriba desde una altura $h0_out a una velocidad $v0_out como se muestra en la figura~\\ref{fig:caidalibre}. La aceleración local de la gravedad es $g_out. Determinar:")
push!(problem,figure("ball","fig:caidalibre","Cuerpo en caída libre");)
push!(problem,question(format,"el tiempo que tarda en caer al suelo (en unitname),", t,"s");)
push!(problem,question(format,"la velocidad que alcanza al tocar el suelo (en unitname),", v,"km/h");)
elseif language==CAT
statement = "Un cos de massa $mass_out és llançat cap amunt des d'una alçada $h0_out a una velocitat $v0_out, com es mostra a la figura~\\ref{fig:caidalibre}. L'acceleració local de la gravetat és $g_out. Determinar:"
figure1 = figure("ball","fig:caidalibre","Cos en caiguda lliure");
question1 = question(format,"el temps que triga a caure a terra (en unitname),", t,"s");
question2 = question(format,"la velocitat que arriba a tenir al tocar a terra (en unitname),", v,"km/h");
push!(problem,"Un cos de massa $mass_out és llançat cap amunt des d'una alçada $h0_out a una velocitat $v0_out, com es mostra a la figura~\\ref{fig:caidalibre}. L'acceleració local de la gravetat és $g_out. Determinar:")
push!(problem,figure("ball","fig:caidalibre","Cos en caiguda lliure");)
push!(problem,question(format,"el temps que triga a caure a terra (en unitname),", t,"s");)
push!(problem,question(format,"la velocitat que arriba a tenir al tocar a terra (en unitname),", v,"km/h");)
elseif language==ENG
else
println("mass = ",mass)
Expand All @@ -29,7 +30,7 @@ function free_fall(mass,h0,v0,language=nothing,format=nothing)
println("t = ",t)
return nothing
end
return [statement,figure1,question1,question2]
return problem

end

Expand All @@ -44,25 +45,26 @@ function inclined_plane(mass,α,language=nothing,format=Unformatted)
Fy=mass*g*cos(α)
a=g*sin(α)

problem=Vector{String}(undef,0)
if language==SPA
statement = "Un bloque de $mass_out desliza sobre un plano cuyo ángulo de inclinación es $α_out. Considerando $g_out, determinar:"
question1=question(format,"la componente paralela de la fuerza debida a la gravedad en unitname",Fx,"N")
question2=question(format,"la componente normal de la fuerza debida a la gravedad en unitname",Fy,"N")
question3=question(format,"la aceleración del bloque suponiendo una superficie sin fricción en unitname.",a,"m/s^2")
push!(problem,"Un bloque de $mass_out desliza sobre un plano cuyo ángulo de inclinación es $α_out. Considerando $g_out, determinar:")
push!(problem,question(format,"la componente paralela de la fuerza debida a la gravedad en unitname",Fx,"N"))
push!(problem,question(format,"la componente normal de la fuerza debida a la gravedad en unitname",Fy,"N"))
push!(problem,question(format,"la aceleración del bloque suponiendo una superficie sin fricción en unitname.",a,"m/s^2"))
elseif language==CAT
statement = "Un bloc de $mass_out llisca sobre un pla que té un angle d'inclinació de $α_out. Considerant $g_out, determinar:"
question1=question(format,"la component paral·lela de la força deguda a la gravetat en unitname",Fx,"N")
question2=question(format,"la component normal de la força deguda a la gravetat en unitname",Fy,"N")
question3=question(format,"l'acceleració del bloc suposant una superfície sense fricció en unitname.",a,"m/s^2")
push!(problem,"Un bloc de $mass_out llisca sobre un pla que té un angle d'inclinació de $α_out. Considerant $g_out, determinar:")
push!(problem,question(format,"la component paral·lela de la força deguda a la gravetat en unitname",Fx,"N"))
push!(problem,question(format,"la component normal de la força deguda a la gravetat en unitname",Fy,"N"))
push!(problem,question(format,"l'acceleració del bloc suposant una superfície sense fricció en unitname.",a,"m/s^2"))
elseif language==ENG
statement = "A $mass_out block is sitting on an incline plane whose angle of inclination is $α_out. Considering $g_out, determine:"
question1=question(format,"the parallel component of the force due to gravity in unitname,",Fx,"N")
question2=question(format,"the normal component of the force due to gravity in unitname,",Fy,"N")
question3=question(format,"the block’s acceleration assuming a frictionless surface in unitname.",a,"m/s^2")
push!(problem,"A $mass_out block is sitting on an incline plane whose angle of inclination is $α_out. Considering $g_out, determine:")
push!(problem,question(format,"the parallel component of the force due to gravity in unitname,",Fx,"N"))
push!(problem,question(format,"the normal component of the force due to gravity in unitname,",Fy,"N"))
push!(problem,question(format,"the block’s acceleration assuming a frictionless surface in unitname.",a,"m/s^2"))
else
println(mass,α)
end
return [statement,question1,question2,question3]
return problem

end

Expand All @@ -76,24 +78,35 @@ function theory_questions(language=nothing,format=Unformatted)
eq[5]=latexify("F=m^2*a")

as = Vector{String}(undef,5);
as[1]="la fuerza con la masa y la aceleración"
as[2]="la fuerza con la aceleración"
as[3]="la fuerza con la masa"
as[4]="la aceleración con la masa"
as[5]="ninguna de las otras"


problem=Vector{String}(undef,0)
if language==SPA
statement = "Teoría de la mecánica clásica."
question1=question(format,"La ley de Newton se puede escribir como:",eq)
question2=question(format,"La ley de Newton relaciona:",as)
as[1]="la fuerza con la masa y la aceleración"
as[2]="la fuerza con la aceleración"
as[3]="la fuerza con la masa"
as[4]="la aceleración con la masa"
as[5]="ninguna de las otras"
push!(problem,"Teoría de la mecànica clàssica.")
push!(problem,question(format,"La ley de Newton se puede escribir como:",eq))
push!(problem,question(format,"La ley de Newton relaciona:",as))
elseif language==CAT
statement = "Teoria de la mecànica clàssica."
question1=question(format,"La llei de Newton es pot escriure com:",eq)
as[1]="la força amb la massa i l'acceleració"
as[2]="la força amb l'acceleració"
as[3]="la força amb la massa"
as[4]="l'acceleració amb la massa"
as[5]="cap de les altres"
push!(problem,"Teoria de la mecànica clàssica.")
push!(problem,question(format,"La llei de Newton es pot escriure com:",eq))
push!(problem,question(format,"La llei de Newton relaciona:",as))
elseif language==ENG
statement = "Theory of classical mechanics."
question1=question(format,"The Newton law can be written as,",eq)
as[1]="force with mass and acceleration"
as[2]="force with acceleration"
as[3]="force with mass"
as[4]="acceleration with mass"
as[5]="none of the others"
push!(problem,"Theory of classical mechanics.")
push!(problem,question(format,"The Newton law can be written as,",eq))
push!(problem,question(format,"The Newton law relates,",eq))
end
return [statement,question1,question2]
W
return problem

end
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Test
generate_quiz(2)
@test isfile("OnlineExamTest_spanish.tex")
@test isfile("OnlineExamTest_spanish.pdf")
rm("OnlineExamTest_spanish_1.pdf",force=true)
rm("OnlineExamTest_spanish_1.tex",force=true)
rm("OnlineExamTest_spanish_1-moodle.xml",force=true)
rm("OnlineExamTest_spanish.pdf",force=true)
rm("OnlineExamTest_spanish.tex",force=true)
rm("OnlineExamTest_spanish-moodle.xml",force=true)
end

0 comments on commit a6c6b23

Please sign in to comment.