Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vungocbinh2009 committed Mar 17, 2021
1 parent 9193572 commit 55af4bb
Show file tree
Hide file tree
Showing 51 changed files with 2,117 additions and 1,661 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Project exclude paths
/venv/
/venv/
/build/
/dist/
/out/
/docs/
1 change: 1 addition & 0 deletions .idea/pytexexam.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 30 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,36 @@ pip install pytexexam

## How to use
```python
from pytexexam import Question, Exam, LatexExam, latexexamutil

# Create questions, answers and solution.
question = Question("Question 1 ?")
question.answer_a("Answer 1", True)
question.answer_b("Answer 2")
question.answer_c("Answer 3")
question.answer_d("Answer 4")
question.shuffle_answer()
question.solution("""
This is the detailed answer of the first question.
""")

# Another way to enter answer options.
question2 = Question("Question 2 ?")
question2.answers(true_answer="A", answer_dict={
"A": "Answer 1",
"B": "Answer 2",
"C": "Answer 3",
"D": "Answer 4"
})
question2.solution("""
This is the detailed answer of the second question.
""")
question2.set_answer_column(2)
question2.shuffle_answer()

# One more question.
question3 = Question("Question 3 ?")
question3.answer_a("Answer 1", True)
question3.answer_b("Answer 2")
question3.answer_c("Answer 3")
question3.answer_d("Answer 4")
question3.set_answer_column(4)
question3.shuffle_answer()

# Create a exam from existing questions.
exam = Exam([question, question2, question3])

# Shuffle the questions.
exam.shuffle_question()

# Create a LatexExam object to export a question as a tex or pdf file (with latex pre-installed)
latex_exam = LatexExam("Simple exam", exam)
# Add AMS math packages, if needed.
latex_exam.add_user_preamble(latexexamutil.ams_math_package())

# Export exam.
latex_exam.export_tex_exam("test1.tex")
latex_exam.export_pdf_exam("test1.pdf")

# Export answer keys
latex_exam.export_tex_answer("answer1.tex")
latex_exam.export_pdf_answer("answer1.pdf")

# Export solutions.
latex_exam.export_tex_solution("solution1.pdf")
latex_exam.export_pdf_solution("solution1.pdf")
import pytexexam.latexexamutil as util
from pytexexam import LatexExamBuilder, ExamExportType

# Create exam builder
builder = LatexExamBuilder()
# You can add preamble here
builder.preamble = util.ams_math_package()
# Exam header
builder.header = "This is a simple header"
# Exam footer
builder.footer = "This is a simple footer"
# You can export exam in tex file or pdf file (need Latex installed)
builder.export_type = ExamExportType.PDF
# Add question
builder.add_question(
question="This is a simple question",
# Answers: This package auto add A, B, C, D ... in answers
answer=["Answer 1", "Answer 2", "Answer 3", "Answer 4"],
# True answer key
true_answer="A",
# present answer in multiple column
answer_column=4,
# Solution of this question
solution="This is solution for this question",
)

# Creste exam, answer and solution!
builder.create_exam("exam1")
builder.create_answer("answer1")
builder.create_solution("solution1")
```

## All package API.
Expand Down
Binary file modified docs/_build/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/.doctrees/index.doctree
Binary file not shown.
8 changes: 2 additions & 6 deletions docs/_build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ ALLPDF = $(addsuffix .pdf,$(ALLDOCS))
ALLDVI = $(addsuffix .dvi,$(ALLDOCS))
ALLXDV =
ALLPS = $(addsuffix .ps,$(ALLDOCS))
ALLIMGS = $(wildcard *.png *.gif *.jpg *.jpeg)

# Prefix for archive names
ARCHIVEPREFIX =
# Additional LaTeX options (passed via variables in latexmkrc/latexmkjarc file)
export LATEXOPTS =
export LATEXOPTS ?=
# Additional latexmk options
LATEXMKOPTS =
LATEXMKOPTS ?=
# format: pdf or dvi (used only by archive targets)
FMT = pdf

LATEX = latexmk -dvi
PDFLATEX = latexmk -pdf -dvi- -ps-


%.png %.gif %.jpg %.jpeg: FORCE_MAKE
extractbb '$@'

%.dvi: %.tex FORCE_MAKE
$(LATEX) $(LATEXMKOPTS) '$<'

Expand Down
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/index.doctree
Binary file not shown.
161 changes: 141 additions & 20 deletions docs/_build/footnotehyper-sphinx.sty
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{footnotehyper-sphinx}%
[2017/10/27 v1.7 hyperref aware footnote.sty for sphinx (JFB)]
[2021/02/04 v1.1d hyperref aware footnote.sty for sphinx (JFB)]
%%
%% Package: footnotehyper-sphinx
%% Version: based on footnotehyper.sty 2017/03/07 v1.0
%% Version: based on footnotehyper.sty 2021/02/04 v1.1d
%% as available at https://www.ctan.org/pkg/footnotehyper
%% License: the one applying to Sphinx
%%
Expand All @@ -16,17 +16,20 @@
%% 3. use of \sphinxunactivateextrasandspace from sphinx.sty,
%% 4. macro definition \sphinxfootnotemark,
%% 5. macro definition \sphinxlongtablepatch
%% 6. replaced an \undefined by \@undefined
%% 6. replaced some \undefined by \@undefined
\newif\iffootnotehyperparse\footnotehyperparsetrue
\DeclareOption*{\PackageWarning{footnotehyper-sphinx}{Option `\CurrentOption' is unknown}}%
\ProcessOptions\relax
\newbox\FNH@notes
\newtoks\FNH@toks % 1.1c
\newdimen\FNH@width
\let\FNH@colwidth\columnwidth
\newif\ifFNH@savingnotes
\AtBeginDocument {%
\let\FNH@latex@footnote \footnote
\let\FNH@latex@footnotetext\footnotetext
\let\FNH@H@@footnotetext \@footnotetext
\let\FNH@H@@mpfootnotetext \@mpfootnotetext
\newenvironment{savenotes}
{\FNH@savenotes\ignorespaces}{\FNH@spewnotes\ignorespacesafterend}%
\let\spewnotes \FNH@spewnotes
Expand All @@ -37,6 +40,7 @@
\@ifpackageloaded{hyperref}
{\ifHy@hyperfootnotes
\let\FNH@H@@footnotetext\H@@footnotetext
\let\FNH@H@@mpfootnotetext\H@@mpfootnotetext
\else
\let\FNH@hyper@fntext\FNH@nohyp@fntext
\fi}%
Expand Down Expand Up @@ -111,14 +115,33 @@
\fi
}%
\def\FNH@spewnotes {%
\endgroup
\if@endpe\ifx\par\@@par\FNH@toks{}\else
\FNH@toks\expandafter{\expandafter
\def\expandafter\par\expandafter{\par}\@endpetrue}%
\expandafter\expandafter\expandafter
\FNH@toks
\expandafter\expandafter\expandafter
{\expandafter\the\expandafter\FNH@toks
\expandafter\def\expandafter\@par\expandafter{\@par}}%
\expandafter\expandafter\expandafter
\FNH@toks
\expandafter\expandafter\expandafter
{\expandafter\the\expandafter\FNH@toks
\expandafter\everypar\expandafter{\the\everypar}}\fi
\else\FNH@toks{}\fi
\expandafter
\endgroup\the\FNH@toks
\ifFNH@savingnotes\else
\ifvoid\FNH@notes\else
\begingroup
\let\@makefntext\@empty
\let\@finalstrut\@gobble
\let\rule\@gobbletwo
\FNH@H@@footnotetext{\unvbox\FNH@notes}%
\ifx\@footnotetext\@mpfootnotetext
\expandafter\FNH@H@@mpfootnotetext
\else
\expandafter\FNH@H@@footnotetext
\fi{\unvbox\FNH@notes}%
\endgroup
\fi
\fi
Expand Down Expand Up @@ -196,27 +219,76 @@
\FNH@endfntext@fntext {\unvbox\z@}%
\endgroup
}%
\AtBeginDocument{%
\let\FNH@@makefntext\@makefntext
\ifx\@makefntextFB\@undefined
\expandafter\@gobble\else\expandafter\@firstofone\fi
{\ifFBFrenchFootnotes \let\FNH@@makefntext\@makefntextFB \else
\let\FNH@@makefntext\@makefntextORI\fi}%
\expandafter\FNH@check@a\FNH@@makefntext{1.2!3?4,}%
\FNH@@@1.2!3?4,\FNH@@@\relax
\let\FNH@prefntext\@empty
\let\FNH@postfntext\@empty
\AtBeginDocument{\iffootnotehyperparse\expandafter\FNH@check\fi}%
\def\FNH@safeif#1{%
\iftrue\csname if#1\endcsname\csname fi\endcsname\expandafter\@firstoftwo
\else\csname fi\endcsname\expandafter\@secondoftwo
\fi
}%
\def\FNH@check{%
\ifx\@makefntextFB\@undefined\expandafter\FNH@check@
\else\expandafter\FNH@frenchb@
\fi
}%
\def\FNH@frenchb@{%
\def\FNH@prefntext{%
\localleftbox{}%
\let\FBeverypar@save\FBeverypar@quote
\let\FBeverypar@quote\relax
\FNH@safeif{FB@koma}%
{\FNH@safeif{FBFrenchFootnotes}%
{\ifx\footnote\thanks
\let\@@makefnmark\@@makefnmarkTH
\@makefntextTH{} % space as in french.ldf
\else
\let\@@makefnmark\@@makefnmarkFB
\@makefntextFB{} % space as in french.ldf
\fi
}{\let\@@makefnmark\@@makefnmarkORI
\@makefntextORI{}% no space as in french.ldf
}%
}%
{\FNH@safeif{FBFrenchFootnotes}%
{\@makefntextFB{}}%
{\@makefntextORI{}}%
}%
}%
\def\FNH@postfntext{%
\let\FBeverypar@quote\FBeverypar@save
\localleftbox{\FBeveryline@quote}%
}%
}%
\def\FNH@check@{%
\expandafter\FNH@check@a\@makefntext{1.2!3?4,}%
\FNH@@@1.2!3?4,\FNH@@@\relax
}%
\long\def\FNH@check@a #11.2!3?4,#2\FNH@@@#3{%
\ifx\relax#3\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
\FNH@bad@makefntext@alert
{\def\FNH@prefntext{#1}\def\FNH@postfntext{#2}\FNH@check@b}%
\ifx\relax#3\expandafter\FNH@checkagain@
\else
\def\FNH@prefntext{#1}\def\FNH@postfntext{#2}%
\expandafter\FNH@check@b
\fi
}%
\def\FNH@checkagain@{%
\expandafter\FNH@checkagain@a
\detokenize\expandafter{\@makefntext{1.2!3?4,}}\relax\FNH@@@
}%
\edef\FNH@temp{\noexpand\FNH@checkagain@a ##1\string{1.2!3?4,\string}}%
\expandafter\def\FNH@temp#2#3\FNH@@@{%
\ifx\relax#2%
\def\FNH@prefntext{\@makefntext{}}%
\else\FNH@bad@makefntext@alert
\fi
}%
\def\FNH@check@b #1\relax{%
\expandafter\expandafter\expandafter\FNH@check@c
\expandafter\meaning\expandafter\FNH@prefntext
\meaning\FNH@postfntext1.2!3?4,\FNH@check@c\relax
}%
\def\FNH@check@c #11.2!3?4,#2#3\relax{%
\ifx\FNH@check@c#2\expandafter\@gobble\fi\FNH@bad@makefntext@alert
\ifx\FNH@check@c#2\else\FNH@bad@makefntext@alert\fi
}%
% slight reformulation for Sphinx
\def\FNH@bad@makefntext@alert{%
Expand Down Expand Up @@ -250,12 +322,61 @@
\noexpand\if@endpe\noexpand\@endpetrue\noexpand\fi
}%
}%
% end of footnotehyper 2017/02/16 v0.99
% some extras for Sphinx :
% \sphinxfootnotemark: usable in section titles and silently removed from TOCs.
\def\sphinxfootnotemark [#1]%
{\ifx\thepage\relax\else\protect\spx@opt@BeforeFootnote
\protect\footnotemark[#1]\fi}%
{\ifx\thepage\relax\else\sphinxfootref{#1}\fi}%
% \sphinxfootref:
% - \spx@opt@BeforeFootnote is from BeforeFootnote sphinxsetup option
% - \ref:
% the latex.py writer inserts a \phantomsection\label{<scope>.<num>}
% whenever
% - the footnote was explicitly numbered in sources,
% - or it was in restrained context and is rendered using footnotetext
%
% These are the two types of footnotes that \sphinxfootnotemark must
% handle. But for explicitly numbered footnotes the same number
% can be found in document. So a secondary part in <scope> is updated
% at each novel such footnote to know what is the target from then on
% for \sphinxfootnotemark and already encountered [1], or [2],...
%
% LaTeX package varioref is not supported by hyperref (from its doc: "There
% are too many problems with varioref. Nobody has time to sort them out.
% Therefore this package is now unsupported.") So we will simply use our own
% macros to access the page number of footnote text and decide whether to print
% it. \pagename is internationalized by latex-babel.
\def\spx@thefnmark#1#2{%
% #1=label for reference, #2=page where footnote was printed
\ifx\spx@tempa\spx@tempb
% same page
#1%
\else
\sphinxthefootnotemark{#1}{#2}%
\fi
}%
\def\sphinxfootref@get #1#2#3#4#5\relax{%
\def\sphinxfootref@label{#1}%
\def\sphinxfootref@page {#2}%
\def\sphinxfootref@Href {#4}%
}%
\protected\def\sphinxfootref#1{% #1 always explicit number in Sphinx usage
\spx@opt@BeforeFootnote
\ltx@ifundefined{r@\thesphinxscope.#1}%
{\gdef\@thefnmark{?}\H@@footnotemark}%
{\expandafter\expandafter\expandafter\sphinxfootref@get
\csname r@\thesphinxscope.#1\endcsname\relax
\edef\spx@tempa{\thepage}\edef\spx@tempb{\sphinxfootref@page}%
\protected@xdef\@thefnmark{\spx@thefnmark{\sphinxfootref@label}{\sphinxfootref@page}}%
\let\spx@@makefnmark\@makefnmark
\def\@makefnmark{%
\hyper@linkstart{link}{\sphinxfootref@Href}%
\spx@@makefnmark
\hyper@linkend
}%
\H@@footnotemark
\let\@makefnmark\spx@@makefnmark
}%
}%
\AtBeginDocument{%
% let hyperref less complain
\pdfstringdefDisableCommands{\def\sphinxfootnotemark [#1]{}}%
Expand Down
8 changes: 2 additions & 6 deletions docs/_build/latex/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ ALLPDF = $(addsuffix .pdf,$(ALLDOCS))
ALLDVI = $(addsuffix .dvi,$(ALLDOCS))
ALLXDV =
ALLPS = $(addsuffix .ps,$(ALLDOCS))
ALLIMGS = $(wildcard *.png *.gif *.jpg *.jpeg)

# Prefix for archive names
ARCHIVEPREFIX =
# Additional LaTeX options (passed via variables in latexmkrc/latexmkjarc file)
export LATEXOPTS =
export LATEXOPTS ?=
# Additional latexmk options
LATEXMKOPTS =
LATEXMKOPTS ?=
# format: pdf or dvi (used only by archive targets)
FMT = pdf

LATEX = latexmk -dvi
PDFLATEX = latexmk -pdf -dvi- -ps-


%.png %.gif %.jpg %.jpeg: FORCE_MAKE
extractbb '$@'

%.dvi: %.tex FORCE_MAKE
$(LATEX) $(LATEXMKOPTS) '$<'

Expand Down
Loading

0 comments on commit 55af4bb

Please sign in to comment.