[Feature Request] : kaobook template to use with emacs orgmode docs
zenny opened this issue · comments
Summary
@fmarotta Kudos to you for creating such a nice text template which is better than tufte-book, imo.
Meanwhile it would be more convenient if this tex template could be integrated to the emacs orgmode so that as self-contained portable kaobook org file can be generated. If someone has done so let me know with the link, and ignore this feature request.
Details
It would be better to create an emacs org-mode template to kaobook
so that one can create a portable orgmode file with all kaobook
files. There is a a very nice orgmode template for tufte-book
in https://github.com/asilata/emacsconf2021.
She has just appended the following under setup
in the orgmode file as follows:
* Setup :noexport:
** Startup
#+startup: noptag overview hideblocks
** Org LaTeX setup
#+latex_class: tufte-book
#+latex_class_options: [openany, a4paper]
#+latex_header: \usepackage{amsmath,amssymb,amsthm,geometry,hyperref,paralist,svg,thmtools,tikz,tikz-cd}
#+latex_header: \usepackage{mathtools}
#+latex_header: \usepackage[capitalise,noabbrev]{cleveref}
#+latex_header: \usepackage{environ} \NewEnviron{abmn}{\marginnote{\BODY}}
#+latex_header: \setcounter{tocdepth}{1}
#+latex_header: \newtheorem{theorem}{Theorem}
#+latex_header: \newtheorem{example}[theorem]{Example}
#+latex_header: \newtheorem{exmpl}[theorem]{Example}
#+latex_header: \newtheorem{definition}[theorem]{Definition}
#+latex_header: \newtheorem{proposition}[theorem]{Proposition}
#+latex_header: \newtheorem{lemma}[theorem]{Lemma}
#+latex_header: \newtheorem{exercise}[theorem]{Exercise}
#+latex_header: \usetikzlibrary{arrows,automata,positioning}
** Export settings
Export into the artifacts directory
#+export_file_name: artifacts/ggm
Add ~tufte-book~ to ~org-latex-classes~ and update ~org-latex-pdf-process~.
#+name: export-setup
#+begin_src emacs-lisp :results silent :var this-year="2021"
(add-to-list 'org-latex-classes
`("tufte-book"
,(string-join
'("\\documentclass{tufte-book}"
"\\usepackage{color}"
"\\usepackage{amsmath,amssymb}")
"\n")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(setq-local org-latex-pdf-process
(let
((cmd (concat "pdflatex -shell-escape -interaction nonstopmode"
" --synctex=1"
" -output-directory %o %f")))
(list cmd
"cd %o; if test -r %b.idx; then makeindex %b.idx; fi"
"cd %o; bibtex %b"
cmd
cmd
"mv *.svg %o/"
"rm -rf %o/svg-inkscape"
"mv svg-inkscape %o/"
(concat "cp %o/%b.pdf ../docs/" this-year "/ggm.pdf"))))
(setq-local org-latex-subtitle-format "\\\\\\medskip
\\noindent\\Huge %s")
(setq-local org-confirm-babel-evaluate nil)
#+end_src
and the following under local variables
as follows:
* Local variables :noexport:
# Local variables:
# eval: (add-hook 'org-export-before-processing-hook (lambda (be) (org-babel-ref-resolve "export-setup")) nil t)
# End:
Quite nifty! So I am seeking inputs from a master of emacs orgmode and LaTeX so that such a beautiful kaobook
template can be made self-contained and portable orgmode file.
Additional context
The amount of convenience my feature may bring with such an self-contained portable org file has been presented by @asilata in https://emacsconf.org/2021/talks/babel/ or can be watched in https://www.youtube.com/watch?v=1Ooi4KAd2FM.
Cheers,
/z
Hi, I managed to produce a pdf using the ggm.org
file from https://github.com/asilata/emacsconf2021by appending the following in the setup
section of the org file:
** Org LaTeX setup
#+latex_class: kaobook
#+latex_class_options: [openany, a4paper]
#+latex_header: \usepackage{amsmath,amssymb,amsthm,geometry,hyperref,paralist,svg,thmtools,tikz,tikz-cd}
#+latex_header: \usepackage{mathtools}
#+latex_header: \usepackage[capitalise,noabbrev]{cleveref}
#+latex_header: \usepackage{environ} \NewEnviron{abmn}{\marginnote{\BODY}}
#+latex_header: \setcounter{tocdepth}{1}
#+latex_header: \newtheorem{theorem}{Theorem}
#+latex_header: \newtheorem{example}[theorem]{Example}
#+latex_header: \newtheorem{exmpl}[theorem]{Example}
#+latex_header: \newtheorem{definition}[theorem]{Definition}
#+latex_header: \newtheorem{proposition}[theorem]{Proposition}
#+latex_header: \newtheorem{lemma}[theorem]{Lemma}
#+latex_header: \newtheorem{exercise}[theorem]{Exercise}
#+latex_header: \usetikzlibrary{arrows,automata,positioning}
** Export settings
Export into the artifacts directory
#+export_file_name: artifacts/ggm
Add ~kaobook~ to ~org-latex-classes~ and update ~org-latex-pdf-process~.
#+name: export-setup
#+begin_src emacs-lisp :results silent :var this-year="2023"
(add-to-list 'org-latex-classes
`("kaobook"
,(string-join
'("\\documentclass{kaobook}"
"\\usepackage{color}"
"\\usepackage{amsmath,amssymb}")
"\n")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
But the produced pdf has some principal features missing from kaobook template which merits kaobook
over tufte-book
template, namely:
- Mini table of contents in the margin at the start of each chapter.
- Chapter headings.
- Huge chapter number
I have attached the produced pdf here. Any suggestion to realize the features missing as above? Thanks!
Hi again,
With some inputs from Tom in https://list.orgmode.org/CACuV5sBZ39QB0bkYXi_8zkTuaYGRbJdvOkgzPymNGB1fGT-KbQ@mail.gmail.com/T/#u (quoted below) who stated that there are some non-standard LaTeX commands:
The kaobook.cls defines non-standard LaTeX commands for some of
its features. Org mode doesn't know about these, so you'll have
to figure out how Org mode can recognize and export them.
...
I haven't used kaobook, so I can't offer specific pointers. I
have used Tufte LaTeX with Org mode, so I can give general
pointers.
A LaTeX class, such as kaobook, typically redefines standard LaTeX
commands and environments, and also defines non-standard commands
and environments. So, you should first check if your system
correctly compiles a pdf from the LaTeX examples supplied with
kaobook. When the LaTeX side is working correctly, then you'll
want to identify non-standard commands and environments defined by
the kaobook class. In the style and class files you might search
for \newcommand and \newenvironment, or the documentation might
identify the user facing non-standard commands and environments.
These are the ones you'll need to configure specially.
I typically use Org mode macros to insert non-standard LaTeX
commands. Here are some I use with non-standard commands from
Tufte LaTex:
#+MACRO: newthought \newthought{$1}
#+MACRO: sidenote \sidenote[$2][$3]{$1}
#+MACRO: marginnote \marginnote[$2]{$1}
#+MACRO: urlnote \sidenote[$2][$3]{\url{$1}}
Non-standard environments are a bit trickier.
First, you might be able to wrap the non-standard environment like
this in your Org mode file:
#+begin_<<kaobook-environment>>
Something that should be wrapped in <<kaobook-environment>>.
#+end_<<kaobook-environment>>
For figures and tables, you can pass an arbitrary argument to
:float. I do this for the Tufte LaTeX marginfigure environment:
#+attr_latex: :float marginfigure :height 1.2in
#+attr_latex: :float marginfigure :options angle=90
#+attr_latex: :placement [ht!] \setfloatalignment{b}
The last example abuses attr_latex to pass a non-standard LaTeX
command that Tufte LaTeX uses to tweak the vertical alignment of
the figure.
Good luck!
hth,
Tom
@fmarotta would you mind enlisting the non-standard LaTeX
commands? Appreciate that.
Cheers,