Code Monkey home page Code Monkey logo

ox-latex-subfigure's Introduction

How

(package-initialize)
(use-package ox-latex-subfigure
  :init
  (setq org-latex-prefer-user-labels t)
  :load-path "~/Dropbox/ProjectWeekends/lisp/ox-latex-subfigure/"
  :config (require 'ox-latex-subfigure))

; (add-to-list 'org-latex-caption-above 'subfigure) ; If you want the caption above the figure
#+LATEX_HEADER: \usepackage{subcaption}
#+NAME: fig:hello
#+CAPTION: Use figure/subfigure instead of tabular, remember to set =:environment=
#+ATTR_LATEX: :environment subfigure :width 0.4\textwidth :align c
| [[~/Desktop/figure_1.png]] | <<fig:hello_subfigure>> tttttt |
| zzzzz                      | [[~/Desktop/figure_1.png]]     |

Ordinary linking works as usual [[fig:hello]]; internal org-mode linking also work [[fig:hello_subfigure]] if one has org-latex-prefer-user-labels set to t.

\begin{figure}[!htb]
\centering
\begin{subfigure}[c]{0.4\textwidth}
\includegraphics[width=.9\linewidth]{/Users/link/Desktop/figure_1.png}
\caption{zzzzz}
\end{subfigure}
\begin{subfigure}[c]{0.4\textwidth}
\includegraphics[width=.9\linewidth]{/Users/link/Desktop/figure_1.png}
\caption{\label{fig:hello_subfigure} tttttt}
\end{subfigure}
\caption{\label{fig:hello}
Use figure/subfigure instead of tabular, remember to set \texttt{:environment}}
\end{figure}

Contribution

Require tools for testing

  • cask
    • install via brew
      brew install cask
              
    • manual install
      cd ~/
      hub clone cask/cask
      export PATH="$HOME/.cask/bin:$PATH"
              

Running test

Below operation flow is recommended.

make                              # Install git-hooks in local .git

git branch [feature-branch]       # Create branch named [feature-branch]
git checkout [feature-branch]     # Checkout branch named [feature-branch]

# <edit loop>
emacs ox-latex-subfigure.el       # Edit something you want

make test                         # Test ox-latex-subfigure via multi version Emacs
git commit -am "brabra"           # Commit (auto-run test before commit)
# </edit loop>

hub fork                          # Create fork at GitHub
git push [user] [feature-branch]  # Push feature-branch to your fork
hub pull-request                  # Create pull-request

Contributions

License

GPL

ox-latex-subfigure's People

Contributors

conao3 avatar diadochos avatar eoma avatar gregoryschwartz avatar linktohack avatar miciah avatar naota avatar tdehaeze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ox-latex-subfigure's Issues

`\centering` below figure if not `org-latex-caption-above`

Hello, thanks for working on this package.

Unfortunately, I have an issue when not including 'subfigure in the org-latex-caption-above list.
In particular, the \centering command is written below the subfigure commands, all the way below right before \end{figure} and therefore doesn't affect the images.

See for example the org snippet

#+NAME: fig:runway-example-both
#+CAPTION: Example of /content/ and /style/ decomposition.
#+ATTR_LATEX: :environment subfigure :width 0.45\textwidth :align c
|  [[./figs/airstrip_imgs.png]]  |  [[./figs/airstrip_imgs2.png]] |
| Maintaining content, changing style. | Maintaining style, changing content. |

and the generated latex snippet

\begin{figure}[htbp]
\begin{subfigure}[c]{0.45\textwidth}
\includegraphics[width=.9\linewidth]{./figs/airstrip_imgs.png}
\caption{Maintaining content, changing style.}
\end{subfigure}
\begin{subfigure}[c]{0.45\textwidth}
\includegraphics[width=.9\linewidth]{./figs/airstrip_imgs2.png}
\caption{Maintaining style, changing content.}
\end{subfigure}
\caption{\label{tab:org5683d81}Example of \emph{content} and \emph{style} decomposition.}
\centering
\end{figure}

The same also happens for the example snippet in the readme. Unfortunately I have not been able to figure out a solution myself.

Export breaks with wrong-type-argument integer-or-marker-p nil

Sorry if i am doing something stupid.
I loaded ox-latex-subfigure and created a little table analog to the README:

#+NAME: fig:nogora
#+CAPTION: Blablabla
#+ATTR_LATEX: :environment subfigure :width 0.4\textwidth :align c
| file:../nogora/ecalhisto.pdf | file:../nogora/ecalhisto-cut.pdf |

When exporting (i.e. C-e l l) I get the error message "wrong-type-argument integer-or-marker-p nil".

It seems to refer to the call to text-properties-at in line 12. of the .el file, with pt being nil.

Below is the backtrace:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
text-properties-at(nil "\begin{center}\n\begin{subfigure}{0.4\textwidth}{c}\n\begin{center}\n\includegraphics[width=.9\linewidth]{../nogora/ecalhisto.pdf}\n\end{center} & \begin{center}\n\includegraphics[width=.9\linewidth]{../nogora/ecalhisto-cut.pdf}\n\end{center}\\\n\end{subfigure}\n\end{center}\n\n")
(plist-get (text-properties-at pt text) :parent)
(setq pt (next-property-change pt text) cell (plist-get (text-properties-at pt text) :parent) table (org-export-get-parent-table cell))
(while (or (not table) (not pt)) (setq pt (next-property-change pt text) cell (plist-get (text-properties-at pt text) :parent) table (org-export-get-parent-table cell)))
(let ((pt 0) cell table attr env limit) (while (or (not table) (not pt)) (setq pt (next-property-change pt text) cell (plist-get (text-properties-at pt text) :parent) table (org-export-get-parent-table cell))) (setq attr (org-export-read-attribute :attr_latex table) env (plist-get attr :environment) limit (string-to-int (or (plist-get attr :limit) "0"))) (if (not (string= "subfigure" env)) text (let ((temp-buffer (generate-new-buffer " temp"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert text) (goto-char 1) (link/latex-table-to-subfigure limit) (buffer-string)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))))
(progn (let ((pt 0) cell table attr env limit) (while (or (not table) (not pt)) (setq pt (next-property-change pt text) cell (plist-get (text-properties-at pt text) :parent) table (org-export-get-parent-table cell))) (setq attr (org-export-read-attribute :attr_latex table) env (plist-get attr :environment) limit (string-to-int (or (plist-get attr :limit) "0"))) (if (not (string= "subfigure" env)) text (let ((temp-buffer (generate-new-buffer " temp"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert text) (goto-char 1) (link/latex-table-to-subfigure limit) (buffer-string)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))))
(if (org-export-derived-backend-p backend (quote latex)) (progn (let ((pt 0) cell table attr env limit) (while (or (not table) (not pt)) (setq pt (next-property-change pt text) cell (plist-get (text-properties-at pt text) :parent) table (org-export-get-parent-table cell))) (setq attr (org-export-read-attribute :attr_latex table) env (plist-get attr :environment) limit (string-to-int (or (plist-get attr :limit) "0"))) (if (not (string= "subfigure" env)) text (let ((temp-buffer (generate-new-buffer " temp"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn ... ... ... ...) (and ... ...))))))))
link/org-export-table-to-subfigure("\begin{center}\n\begin{subfigure}{0.4\textwidth}{c}\n\begin{center}\n\includegraphics[width=.9\linewidth]{../nogora/ecalhisto.pdf}\n\end{center} & \begin{center}\n\includegraphics[width=.9\linewidth]{../nogora/ecalhisto-cut.pdf}\n\end{center}\\\n\end{subfigure}\n\end{center}\n\n" latex (:export-options nil :back-end [cl-struct-org-export-backend latex nil ((bold . org-latex-bold) (center-block . org-latex-center-block) (clock . org-latex-clock) (code . org-latex-code) (drawer . org-latex-drawer) (dynamic-block . org-latex-dynamic-block) (entity . org-latex-entity)
...

Caption / shortcaption export not working

When exporting normal figures I can insert a shortcaption for the table of figures (whole caption looks pretty bad there.
With subfigure this does not work. When inserting #+caption[short]long then neither gets exported.
I tried with

+ATTR_LATEX: :caption \caption[short]long

and also no luck...

Minimal example:

+CAPTION[This short caption exports well]: Longcaption

+LABEL: fig:figure

figure 1

+CAPTION[Short caption]: Long caption that is so long that it does not fit or look good in the table of figures, needing a short caption for that...

+LABEL: fig:subfigure_example1

+ATTR_LATEX: :environment subfigure :width 0.49\linewidth :align b

| This is a subcation of the first image | This is a subcaption of the second image. |
| figure 1 | figure 2 |

Default subfigure options

I think it would be nice if it were possible to add a default subfigure options using something like like:

#+BIND: org-subfigure-default-option "height=2cm"

Then, if the third row of a table is not set:

#+name: fig:force_deflection_characteristics
#+caption: Force-deflection characteristics
#+attr_latex: :environment subfigure :width 0.32\linewidth :align t
| file:dry_friction.png             | file:viscous_damper.png               |
| <<fig:dry_friction>> Dry friction | <<fig:viscous_damper>> Viscous damper |

It would produce:

\begin{figure}[htbp]
\centering
\begin{subfigure}[t]{0.32\linewidth}\centering
\includegraphics[height=2cm]{dry_friction.png}
\caption{\label{fig:dry_friction} Dry friction}
\end{subfigure}
\begin{subfigure}[t]{0.32\linewidth}\centering
\includegraphics[height=2cm]{viscous_damper.png}
\caption{\label{fig:viscous_damper} Viscous damper}
\end{subfigure}
\caption{\label{fig:force_deflection_characteristics}
Force-deflection characteristics}
\end{figure}

Thanks :)

Setting subfigure width

Hi,
First of all, thank you for this package, very useful! :)

I would like to be able to tune the size of the subfigures, ideally individually, but at least setting one default size.

For now, it seems it takes the default width defined by =org-latex-image-default-option= or =org-latex-image-default-width=.

Can I tune that for subfigures? Like having one variable =org-latex-subfigure-width=?

Thanks

Export without \centering (with my setup)

In my org-mode setup I need to have the option "Org Latex Tables Centered" disabled, because of issues when using threeparttable and sidewaystable (see link)
https://www.mail-archive.com/[email protected]/msg104079.html

To still center all float environments I inserted:

+LATEX_HEADER: \makeatletter

+LATEX_HEADER: \g@addto@macro@floatboxreset\centering

+LATEX_HEADER: \makeatother

But this does not work with ox-latex-subfigure, and :align option only allows for t,c,b
Is there some possibility to get \centering on export with "Org Latex Tables Centered" disabled?
Or could you indicate what to change in your code to get that behaviour (I see \centering at various points, but do not know where to change it). In my use case I would always center align, so no need for any conditional....

brakes table.el

Hello. Thank you very much for your package.
I want to let you know that it is currently braking my table.el for some reasons. I commented the sections of my .emacs where ox-latex-subfigure is, and table.el is working again. I get a wrong-type-argument integer-or-marker-p nil . I checked the issues in the repo, and I don't think that it's the same as #6

I'm attaching my configuration for org-mode.
org-mode.txt

Add this package to MELPA

Hi!
I like this package. Do you have an idea to add this package to MELPA?
Registering with MELPA allows more Emacs users to use this package.

If you think it is troublesome, I will Fork and register. If you don't like having too many repositories, you can help with ongoing maintenance by making me a collaborator.

Best,

exporting to table

Hello,

I tried ox-latex-subfigure today. I loaded it with the code you provided and tried your minimal example,
changing path of both of course. It still exports to table...
What am I doing wrong?
\begin{table}[!htbp]
\caption{\label{fig:hello}
Use figure/subfigure instead of tabular, remember to set \texttt{:environment}}
\begin{subfigure}{0.4\textwidth}{c}
\includegraphics{/home/mcg/picture1.jpg} & \includegraphics{/home/mcg/picture2.jpg}
tttttt & zzzzzz
\end{subfigure}
\end{table}
\end{document}

Additionnal \end{figure}

Hi,
I just updated to last version, and I have a problem of additional \end{subfigure} added as shown in the below generated latex code.

\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.3\linewidth}\centering
\includegraphics[\end{subfigure}
]{nyquist_point.png}
\caption{\label{fig:nyquist_point} Point receptance}
\end{subfigure}
\begin{subfigure}[b]{0.3\linewidth}\centering
\includegraphics[]{nyquist_transfer.png}
\caption{\label{fig:nyquist_transfer} Transfer receptance}
\end{subfigure}
\caption{\label{fig:nyquist_frf_plots}
Nyquist FRF plot for proportionally-damped system}
\end{figure}

I had not this problem previously.

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.