org mode - side by side figure captions for latex export - emacs

I have found how to do side by side figures for latex export as described here:
http://permalink.gmane.org/gmane.emacs.orgmode/52978
But the problem is that when I try to attach a #+CAPTION or #+NAME / #+LABEL, the output gets garbled with the caption moved across multiple lines as well as the pictures.
#+CAPTION: Some desription.
#+LABEL: mylabel
#+ATTR_LATEX: width=5cm
| [[./test.png]] | [[./test2.png]] |
I tried the same syntax with a single figure and it works fine:
#+CAPTION: Some desription.
#+LABEL: mylabel
#+ATTR_LATEX: width=5cm
[[./test.png]]
Does anyone know how to get this to work?

AFAICT, the hack described in the link above (and I'm allowed to call it that, since I came up with it in the first place :-) ) works in current versions of org (9.0.3+ or thereabouts) with some customizations:
By default, images are centered (so the \includegraphics is wrapped inside a center environment), but that breaks images in tables. In the example below, I turn off the centering using a #+BIND to set org-latex-images-centered to nil.
The #+ATTR_LATEX (which, if I'm not mistaken, should look like this in "modern" org syntax: #+ATTR_LATEX: :width 5cm) applies to the table, so the images get the default size of 0.9\ linewidth, and with two of them, that's more than the width of the page. So in the example below, I use another #+BIND to set the default size of the images, but I think there is a bug: they are not set to 5cm as specified, but to their "natural" size. In any case, even if this is a bug, it is not really germane to the question.
Note that the caption is attached to the table that contains the two images: there might be a way to attach separate captions to the images, but I don't know for sure.
With all that in place, the following example file works for me (and it also shows a way to get a single centered image, even if you've disabled centering globally, as I do with the first #+BIND):
#+BIND: org-latex-images-centered nil
#+BIND: org-latex-image-default-width 5cm
* side by side figures in latex
#+CAPTION: An image
#+NAME: myimage
#+ATTR_LATEX: :width 8cm :center t
[[./images/test1.png]]
#+CAPTION: Some description
#+NAME: mytable
| [[./images/test1.png]] | [[./images/test2.png]] |
EDIT: There is no bug - I made a mistake in the #+BIND - it should be
#+BIND: org-latex-image-default-width "5cm"
The quotes are necessary!

Instead of putting images in a table, I centered a pair of images using this question from the TeX site on StackExchange..
I made a 1x1, transparent pixel at this web site and saved it to a file named empty_fig.png. I told org-mode to make it really tiny with #+ATTR_LATEX: :height 0.0001in. I then captioned that figure, right under the pair that I was not able to caption.
#+begin_center
#+ATTR_LATEX: :height 0.4\textwidth :center nil
[[file:Screenshot from 2019-04-30 18-25-36.png]]
#+ATTR_LATEX: :height 0.4\textwidth :center nil
[[file:Screenshot from 2019-04-30 18-25-46.png]]
#+end_center
#+CAPTION: Example frames
#+LABEL: fig:video_pair
#+ATTR_LATEX: :height 0.0001in
[[file:empty_fig.png]]
I realize that this is hacky and it is exposed to having the image pair separated from the empty image when LaTeX re-flows the page, but that will be a different bridge to cross. It's an alternative that doesn't entail BIND, i.e., changing the internal state variables of org-mode.

Figured out a neat solution inspired by this post:
#+caption: Caption shared by both figures
#+BEGIN_EXPORT html
<img src="./fig1.png" width="48%"> <img src="./fig2.png" width="48%">
#+END_EXPORT
I later realized it only works on Hugo site when displaying as HTML and does not work on a normal org file.

Related

How can I stop org mode from moving my figures to the last page?

I'm currently trying to write up my thesis in emacs org-mode, and have run into some problems with file inclusions.
When I include figures with:
#+NAME: fig:banana
#+CAPTION: this is a figure caption
[[/path/to/image.png]]
(or using a pdf) it works fine. But when I insert another image, it is somehow moved to the end of the file instead of being inserted where it is called.
My pdf-export process (in my ~/.emacs file) looks like this:
(setq org-latex-pdf-process
'("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f"))
Any ideas on how to fix this?
A friend of mine pointed me to the LaTex package placeins.
#+LATEX_HEADER: \usepackage{placeins}
* section 1
** hi!
#+TITLE: fig:banana
#+CAPTION: this is a banana figure
[[/link/to/banana.png]]
\FloatBarrier
* section 2
The FloatBarrier stops floats (figures are floats) from jumping over them. I will need to look into passing [tbh] options to figures from org mode further.
Check the org-mode manual on how to pass placement options such as [h], [t] etc. to theLaTeX compiler.
If you're not sure how to control where figures (more precisely, floats) get placed by LaTeX, please refer to any introduction.
Or do you want the figure to be placed where you include it? If so, you might not need it to be a float.

Mark-up for bold and italic in emacs org-mode

In emacs org-mode, we can use mark-ups to set Emphasis and monospace.
e.g.
*bold*
/italic/
How can we make a word both bold and italic?
It seems neither */.../* nor /*...*/ works.
In fact, both of these do work.
/*test*/
exports to HTML as
<i><b>test</b></i>
*/test/* works similarly. LaTeX / PDF export also works as you expect.
Org itself doesn't fontify both the bold and italic, but the semantics are fine.
Expanding on #Chris answer covering semantics being there, if you're interested in visible fontification effect inside your org notes, you have three approaches:
Highlight parts of your text
Nesting works nicely as long as you don't need to start / end two tags at once.
Use multiple tags with escape symbols
The closest you can get is
The code is:
*\ /\ _\ ~fontification can be nested~\_\/\*
So you need \​​ ​ (backslash and space) to escape following opening tags and \ (backslash) to escape following closing tags.
The need for space is annoying, and in it looks like this when exported to html:
So yes, you can have multiple mark-ups at once, but you have to choose between seeing the effect in emacs or having it nicely formated on export.
Modify how markup looks in emacs
Alternatively you could change how mark-up looks in emacs without modyfing exporting format, i.e. to make bold look red you'd need this:
(add-to-list 'org-emphasis-alist
'("*" (:foreground "red")
))
as covered in this great question and answer.

How to change default face for embolden text in Emacs?

I do love thin fonts, so I have following customisation in my .emacs:
(set-frame-font "NK57 Monospace-14:weight=light" t)
This works as expected, however this does not tells Emacs that it should render embolden text with lighter weight too, e.g. to use medium instead of regular weight, so there is dramatically difference in weights, see picture below.
How can I tweak this?
Well, it is possible to customise default bold face using customize-face command as was mentioned by lawlist (i.e. Easy Customization).
However, this is not enough in most cases, because of some packages or themes could introduce another customisations, which overrides default one (e.g. font-lock-function-name-face, font-lock-keyword-face) and could be found in face customisation menu too.

LaTeX math mode ($...$) font color in org mode

I have just started using org-mode and it looks awesome. The only issue that I have so far is that when I write a text in mathmode ($...$) it appears in the standard-text font color.
So, I would like to make org-mode to identify the mathmode text and be able to present it in some other color. Note that I don't need to change the color of the actual equation, just the source text in org-mode.
Here is an example of how the text is currently presented
A paper by Rohnert, titled "Moving a disc between polygons" introduces
a structure using which one can generate a solution (path) for
a given query in $O(\log n) + k$ time.
and how I would like it to look
A paper by Rohnert, titled "Moving a disc between polygons" introduces
a structure using which one can generate a solution (path) for
a given query in $O(\log n) + k$ time.
(Note that I would prefer to display in some given color, e.g. red, and not bold face.)
In Emacs version 24.4 and later, this is controlled via the variable org-highlight-latex-and-related:
Non-nil means highlight LaTeX related syntax in the buffer. When non
nil, the value should be a list containing any of the following
symbols:
`latex' Highlight LaTeX snippets and environments.
`script' Highlight subscript and superscript.
`entities' Highlight entities.
So something like
(eval-after-load 'org
'(setf org-highlight-latex-and-related '(latex)))
in your init should help. Such code is formatted according to the face org-latex-and-related.
In earlier versions, the variable org-highlight-latex-fragments-and-specials, which is a simpler nil / non-nil variable:
(eval-after-load 'org
'(setf org-highlight-latex-fragments-and-specials t))
In this case, the face org-latex-and-export-specials is used.

FlySpell in Org-Mode recognize latex syntax like auctex

Original Response:
I was trying to figure out how in auctex mode latex doesn't seem to highlight any latex functions with flyspell turned on. Is this a custom dictionary file or how is this implemented? Can this be easily incorporated into an org-mode file so it doesn't highlight inserted latex code that will get exported.
Edit:
Simple example taken from top of file and in the text. Basically so latex syntax like ref or label inside {} won't be spell checked (this has been fixed by using (setq ispell-parser tex). Then also setting up a function that specific labels with #+ as the first text on the line won't be checked. I would want the caption checked but not #+LABEL: or #+TYP_TODO: (not shown. Also a way to add TODO keywords to not get checked. I can think of a way to do this is on startup add these to the LOCALWORDS: ispell places at the bottom of the file if not already there but is there an easier or better way to do this.
#+TAGS: NOTE REPORT export noexport MEETING
#+TYP_TODO: TODO Weekly WAITING NEXT | Meeting DONE
#+STARTUP: hidestars content hideblocks
The exponential running mean is shown for various alpha values in Figure \ref{fig:saturation_varying_alphaval_00f6set2}.
#+CAPTION: Plot of varying alpha values for the exponential running mean ($EM$) with $S_{min} = 0.0008 \text{ and } P_m = 0.20$
#+LABEL: fig:saturation_varying_alphaval_00f6set2
#+ATTR_LaTeX: width=0.4\textwidth placement=[h!tb]
flyspell internally uses ispell-mode. To change the way that ispell parses files set the variable ispell-parser to 'tex.
(add-hook 'org-mode-hook (lambda () (setq ispell-parser 'tex)))
Most likely auctex is using flyspell-mode-predicate to define what portions of the buffer shouldn't be spellchecked. (This answer shows how to do something similar for MoinMoinWiki.) org-mode already has such a function, org-mode-flyspell-verify, which apparently doesn't work properly for you... A quick look at the source suggests that org-remove-flyspell-overlays-in should be called for buffer portions containing code samples etc.
Sorry about the handwavy answer; marking this as community wiki to invite improvements.