Edgar Rios cc4a401d08 ignore .lof | 8 months ago | |
---|---|---|
.gitignore | 8 months ago | |
LICENSE | 4 years ago | |
README.org | 8 months ago | |
README.pdf | 8 months ago | |
ex-bug-long-width.png | 2 years ago | |
ex-lof.png | 2 years ago | |
ex-no-subcap.png | 2 years ago | |
ex-plain.png | 2 years ago | |
ox-latex-subfig.el | 8 months ago | |
transmission.svg | 3 years ago |
You can read this text more comfortably with Emacs, just donwload README.org.
This package turns an Org table (https://orgmode.org) into a series of \LaTeX subfloat
. It also enables subcaptions, different widths for the sub-figures and to pass options to the \LaTeX includegraphics
and includesvg
commands.
The program is actually a filter for Org tables. It uses regular expressions to replace the text that Org's \LaTeX exporter produces with suitable minipage
and subfloat
environments.
To install, you can clone this repository using the Linux terminal:
torsocks git clone https://www.notabug.org/broncodev/ox-latex-subfig
That will create an ox-latex-subfig
sub-directory where you typed that command. Then, you can add one of these 2 into your Emacs init file (usually =.emacs= or init.el=; you can find it in the Emac's =user-init-file
variable):
(require 'package)
#+begin_src emacs-lisp (with-eval-after-load "ox" (add-to-list 'load-path "/path/to/use-package") (require 'ox-latex-subfig) ;; ;; If you want the caption above the figure ;; (add-to-list 'org-latex-caption-above 'subfig) ) #+end_src
use-package.el
(https://github.com/jwiegley/use-package)#+BEGIN_SRC emacs-lisp ;; Add use-package to `load-path' (add-to-list 'load-path "/path/to/use-package") ;; Load `use-package' (require 'use-package) ;; Enable (use-package ox-latex-subfig :init (setq org-latex-prefer-user-labels t) :load-path "/path/to/ox-latex-subfig/" :after "ox" :config (require 'ox-latex-subfig) ;; ;; If you want the caption above the figure ;; (add-to-list 'org-latex-caption-above 'subfig) ) #+END_SRC
In your Org file, you'll need to load the subfig
package. This is included in many GNU/Linux distibutions. Techincally, the caption
and hyperref
packages are also needed for captions and links in the PDF, but no further configuration is needed in vanilla Org (check org-latex-packages-alist
and org-latex-default-packages-alist
).
,#+LATEX_HEADER: \usepackage{subfig}
pacman -S texlive-core
sudo apt-get install texlive-generic-extra
If you are going to use svg files, you will need the \LaTeX svg package. You can get it with the texlive-latexextra
in some distributions
pacman -S texlive-latexextra
,#+LATEX_HEADER: \usepackage{svg} ,#+LATEX_HEADER: \svgpath{{my/path1}{my/figures/path}}
There is a transmission.svg
included in this repository, which comes from the transmission-gtk package (http://www.transmissionbt.com/). If you convert that file to png (with ImageMagick: convert transmission.svg transmission.png
), the examples below will show an image. You can also replace transmission.png
and transmission.svg
with something that you prefer (try example-image-a.png
).
,#+LATEX_HEADER: \usepackage{svg}
,#+LATEX_HEADER: \usepackage{subfig}
,#+NAME: fig:hello
,#+CAPTION: This caption has two
,#+caption: #+caption:
lines
,#+ATTR_LATEX: :environment subfig :width 0.3\textwidth
| |
| Description |
Description |
\begin{figure}[htbp] \noindent\null\hfill% \begin{minipage}[l]{0.3\textwidth}% \centering% \subfloat[Description]{% \includesvg[width=\textwidth]{transmission}}% \end{minipage}\hfill\null% \caption{\label{fig:hello}This caption has two \texttt{\#+caption:} lines}% \end{figure}%
<<my-link>>
)\includegraphics
or \includesvg
)lofdepth
to the \LaTeX subfig
package.:align
option for #+ATTR_LATEX:
(may have more than one value. For example: =:align bt=; see Ex. ex-lof):width
option for #+ATTR_LATEX:
. If more than one value is provided, it has to be a comma-separated list with no spaces (see Ex. ex-empty-caption-diff-width). The first value corresponds to the first column, and so on.,#+latex_header: \usepackage{svg} ,#+latex_header: \usepackage[lofdepth]{subfig}
<>
,#+latex: \listoffigures
,#+NAME: fig:ex-lof ,#+CAPTION: Getting sub-captions, links, a list of figures and options ,#+ATTR_LATEX: :environment subfig :width 0.4\textwidth :align b | | | | Description<> | This is a very long description which should not fit on a single line on a regular page | | width=0.3\textwidth | | This sub-figure is here (Fig. subfig-ex-lof)
Description | This is a very long description which should not fit on a single line on a regular page |
width=0.3\textwidth | |
his sub-figure is here (Fig. subfig-ex-lof |
\listoffigures
\begin{figure}[htbp] \noindent\null\hfill% \begin{minipage}[b]{0.4\textwidth}% \centering% \subfloat[Description]{% \includesvg[width=0.3\textwidth]{transmission}}% \end{minipage}\hfill% \begin{minipage}[b]{0.4\textwidth}% \centering% \subfloat[This is a very long description which should not fit on a single line on a regular page]{% \includesvg[width=\textwidth]{transmission}}% \end{minipage}\hfill\null% \caption{\label{fig:ex-lof}Getting sub-captions, links, a list of figures and options}% \end{figure}% This sub-figure is here (Fig. \ref{subfig-ex-lof})
,#+latex_header: \usepackage{subfig}
<>
,#+NAME: fig:ex-empty-caption-diff-width ,#+CAPTION: Empty caption, link and different widths ,#+ATTR_LATEX: :environment subfig :width 0.4\textwidth,0.5\textwidth :align b | | | | | | | width=0.9\textwidth | width=0.8\textwidth |
\begin{figure}[htbp] \noindent\null\hfill% \begin{minipage}[b]{0.4\textwidth}% \centering% \subfloat[]{% \includesvg[width=0.9\textwidth]{transmission}}% \end{minipage}\hfill% \begin{minipage}[b]{0.5\textwidth}% \centering% \subfloat[]{% \includesvg[width=0.8\textwidth]{transmission}}% \end{minipage}\hfill\null% \caption{\label{fig:hello}Empty caption, link and different widths}% \end{figure}%
This is a hack, but works to have two subfigures on top of each other.
,#+LATEX_HEADER: \usepackage{subfig} ,#+LATEX_HEADER: \usepackage{svg}
<>
,#+CAPTION: Two images on top of each other ,#+ATTR_LATEX: :environment subfig :width \textwidth :align b | | | Above. \medskip | | width=0.4\textwidth | | | | Underneath. | | width=0.3\textwidth |
\begin{figure}[htbp] \noindent\null\hfill% \begin{minipage}[b]{\textwidth}% \centering% \subfloat[Above. \medskip]{% \includesvg[width=0.4\textwidth]{transmission}}% \end{minipage}\hfill% \begin{minipage}[b]{\textwidth}% \centering% \subfloat[Underneath.]{% \includesvg[width=0.3\textwidth]{transmission}}% \end{minipage}\hfill\null% \caption{Two images on top of each other}% \end{figure}%
If you were using \LaTeX subcaption
(now deprecated; the reason to create ox-latex-subfig
) through ox-latex-subfigure
as I was, you may need to update your Org documents. Here is a convenient one-liner that can help you (files may have spaces in their names):
find . -type f \-name '*.org' -exec \ grep -l '\(:environment subfigure\|usepackage.subcaption\)' \{\} + | \ while IFS= read -r -d$'\n' file; do printf "$file\n"; sed -i 's/:environment subfigure/:environment subfig/g; s/usepackage.subcaption./usepackage{subfig}/g;' "$file"; done
#+CAPTION:
or #+name:
are neededTo fix this, just add either #+caption:
or #+name:
(not empty).
,#+LATEX_HEADER: \usepackage{svg} ,#+LATEX_HEADER: \usepackage{subfig} ,#+ATTR_LATEX: :environment subfig | | | Description |
\begin{center} \begin{subfig}{l} \toprule \begin{center} \includesvg[width=.9\linewidth]{transmission} \end{center}\\ Description\\ \bottomrule \end{subfig} \end{center}
:width
(or :align
)In this example, one would expect to have 2 pictures atop and 2 at the bottom. However, only 2 values of :width
are provided. When the number of :width
(or :align
) values is less than the number of sub-figures, the last value is used for the remaining pictures. Since there are 4 pictures and only 2 values here (namely 0.4\textwidth
and 0.6\textwidth
) the latter is used for the figures at the top right, bottom left and bottorm right. \LaTeX still uses the last width value and the pictures "overflow" the margin.
Although it is proper \LaTeX code, it will not render what one would expect. Trying to minimise the issue with the options which are passed to includesvg
or includegraphics
will not change the fact that the minipage
tries to take 0.6\textwidth
.
,#+latex_header: \usepackage{subfig}
,#+NAME: fig:hello
,#+CAPTION: This caption has two
,#+caption: #+caption:
lines
,#+ATTR_LATEX: :environment subfig :width 0.4\textwidth,0.6\textwidth :align b
| | |
| Top left | Top right |
| width=0.9\textwidth | width=0.8\textwidth |
| | |
| Bottom left | Bottom right |
| width=0.7\textwidth | width=0.85\textwidth |
\hline
\begin{figure}[htbp] \noindent\null\hfill% \begin{minipage}[b]{0.4\textwidth}% \centering% \subfloat[Top left]{% \includesvg[width=0.9\textwidth]{transmission}}% \end{minipage}\hfill% \begin{minipage}[b]{0.6\textwidth}% \centering% \subfloat[Top right]{% \includesvg[width=0.8\textwidth]{transmission}}% \end{minipage}\hfill% \begin{minipage}[b]{0.6\textwidth}% \centering% \subfloat[Bottom left]{% \includesvg[width=0.7\textwidth]{transmission}}% \end{minipage}\hfill% \begin{minipage}[b]{0.6\textwidth}% \centering% \subfloat[Bottom right]{% \includesvg[width=0.85\textwidth]{transmission}}% \end{minipage}\hfill\null% \caption{\label{fig:hello}This caption has two \texttt{\#+caption:} lines}% \end{figure}%
\hline
file:ex-bug-long-width.png
The row following the figure is destined to set the description (and label, a.k.a. reference or tag). If they are switched, the program will place them in \LaTeX code, but that code would be invalid.
,#+latex_header: \usepackage{subfig}
,#+NAME: fig:hello
,#+CAPTION: This caption has two
,#+caption: #+caption:
lines
,#+ATTR_LATEX: :environment subfig :width 0.4\textwidth,0.5\textwidth
| | |
| width=0.5\textwidth | |
| Left subfigure | |
The program expects that links to subfigures are on the same row.
,#+latex_header: \usepackage{subfig}
,#+NAME: fig:hello
,#+CAPTION: This caption has two
,#+caption: #+caption:
lines
,#+ATTR_LATEX: :environment subfig :width 0.4\textwidth,0.5\textwidth
| | |
| width=0.5\textwidth | |
| Left subfigure | |
In general, providing either
a) only one option for :width
and :align
, or
b) the same number of options (to :width
and :align
) as there are figures
is the best way for the program to work. If there are more of these options than figures, they will be disregarded. If there are less, the last is used for the remaining figures. This can be a feature, but some may find unexpected results.
If you look at the code, there are ways to make it fail on purpose! Try these:
If you really want, you can pass a macro or command as a sub-caption (description) or option (to includegraphics
or includesvg
), but that will be at your own risk
,#+LATEX_HEADER: \usepackage{svg}
,#+LATEX_HEADER: \usepackage{subfig}
,#+NAME: fig:hello
,#+CAPTION: This caption has two
,#+caption: #+caption:
lines
,#+ATTR_LATEX: :environment subfig
| | file:transmission.svg]] |
| \end{subfig} | Right subcaption |
| \end{table} | |
,#+LATEX_HEADER: \usepackage{svg}
,#+LATEX_HEADER: \usepackage{subfig}
,#+NAME: fig:hello
,#+CAPTION: This caption has two
,#+caption: #+caption:
lines
,#+ATTR_LATEX: :environment subfig
| | file:transmission.svg]] |
| \end{subfig} | \end{table} |
,#+LATEX_HEADER: \usepackage{svg}
,#+LATEX_HEADER: \usepackage{subfig}
,#+NAME: fig:hello
,#+CAPTION: This caption has two
,#+caption: #+caption:
lines
,#+ATTR_LATEX: :environment subfig
| | file:transmission.svg]] |
| | \end{subfig} |
| option=val | \end{table} |
:width
, one could use a comma-separated list for :align
to provide horizontal and vertical alignment. Right now, only vertical alignment can be providedorg-mode
9
compatibility\hfill
and \null
GNU General Public License Version 3 (GPL v.3) GNU Free Document License 1.3 (https://www.gnu.org/licenses/fdl-1.3.html)