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

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.

Related

How can I make the headings in xelatex document align at the left?

Hello, I'm using Emacs's org mode for editing my documents. As you can see I have a first level heading (the blueish color) and a second level heading (yellow).
My table of contents doesn't show up and I have no idea why, but the biggest issue is aligning those headings to the left in the PDF and make them bold.
I'm using the following xelatex settings in the Emacs config if this helps:
"article"
"\\documentclass[11pt,a4paper]{article}
\\usepackage{fontspec}
\\setmainfont{Charis SIL}
\\usepackage{geometry}
\\geometry{a4paper, left=0.67in, right=0.67in,
top=0.5in, bottom=0.67in}
\\setlength{\\parindent}{0pt}
Here's the content of the .TEX file that is also generated along the PDF.
% Created 2020-11-14 Sat 22:47
% Intended LaTeX compiler: xelatex
\documentclass[11pt,a4paper]{article}
\usepackage{fontspec}
\setmainfont{Charis SIL}
\usepackage{geometry}
\geometry{a4paper, left=0.67in, right=0.67in,
top=0.5in, bottom=0.67in}
\setlength{\parindent}{0pt}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\author{Author}
\date{\today}
\title{Test Document}
\hypersetup{
pdfauthor={Author},
pdftitle={Test Document},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 27.1 (Org mode 9.3)},
pdflang={English}}
\begin{document}
\maketitle
\tableofcontents
Org mode, as it says on the official web page is for keeping notes, maintaining TODO lists, doing project planning, and authoring with a fast and effective plain-text system. Beginning with Emacs 22.2 and XEmacs 22.1 it has been part of Emacs. The following is a simple tutorial to help you get started using Emacs and Org mode.
\begin{enumerate}
\item The absolute minimum you need to know about Emacs
\label{sec:orgf515372}
The absolute minimum you need to know about Emacs, to be able to do anything, is more then you need to know about many other applications. But, you might compare it to a regular toy and lego. Lego is harder to begin with (you start with a box with little plastic pieces), but in the long run, you can do more with it.
Emacs is heavy on shortcuts. starting out, that is rather annoying, but in time you'll notice you start to use the mouse less and less, and you actually start to work quicker.
\begin{enumerate}
\item Starting Org mode
\label{sec:orgb4df8b1}
New shortcuts in this chapter:
C-x C-s – save document
C-x C-f – open document
\end{enumerate}
\end{enumerate}
\end{document}

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.

how to freely format comments in cc-mode

I'm quite new to cc-mode and I'd like to configure it to allow me to freely format and use tabs in multiline comments. This is important to me because I want to use cog.py in my source file and need to be able to format the python source in the comment correctly. I'd be ok with comments not beeing autoindented at all, however I'd like to keep auto indenting the rest of the source code.
Example:
...
/*
[[[cog
import cog
for x in ['a','b','c']:
>cog.outl(x)
]]]
*/
...
In the line marked with > I'd like to press TAB to indent the line. cc-mode simply does nothing at all if i do so. I could use spaces there (which is inconvenient) but every (semi-)automatic re-indentation of this block would cause the spaces to vanish and therefore the python code to be incorrectly indented (which is what happens if i happen to press tab somewhere on this line after indenting it with spaces).
I tried to start emacs without my .init to be sure this is default behavior and not modified by my configuration so far. I've done google searches and read the documentation of the cc-mode variables / functions I stumbled upon (cc-mode online docs) while searching for a solution (i.e. c-indent-comments-syntactically-p, c-indent-command, c-tab-always-indent,...) but none of these seemed to solve my question.
EDIT1:
Thanks to abo-abo's idea of a "multi-major-mode" setup i've stumbled upon mmm-mode and have set up automatic switching to python mode for a cog section, which fixes most of my problems.
The only remaining problem is reindenting the whole file or a region containing a cog section. Can I somehow tell cc-mode to not change anything in comments while reindenting the file? mmm-mode + that would be a perfect solution for me.
You can use M-i to force a tab indent on the lines that you want, so you can use it to indent your comments.
You can also change your comments to use // instead. Just select your python code snippet, and do M-x comment-region:
// def foo(x):
// print 'hi'
Then the autoindent won't mess up your indentation.

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.

Emacs Gnus Faces (Fonts)

The slrn newsreader has an attractive interface with different colours for the author, subject and date columns when browsing list of articles in a newsgroup. I am looking for the Emacs font/face variables for these fields in gnus, but have not been able to find them. The gnus manual for faces does not list the available faces and none of the faces list in Emacs (M-x customize-face gnus-... looks relevant. I am using gnus 5.13 in Emacs 23.2.1.
(This question is not related to displaying "faces" (icons/avatars) in Emacs or gnus.)
Solved: See my answer below.
I think they're scattered a bit in the gnus codebase. The faces used in the article buffer are probably in gnus-art.el, etc.
It sounds like your biggest problem is that there are specific faces that you can't find the symbol for. You can always do M-x describe-face to see what is under the cursor to solve that problem.
Also, (face-list) returns a list of all defined faces. You could scan that list looking for things that look like likely candidates for the particular faces you're interested in.
The format string for various elements in gnus can be customized by modifying the appropriate variable. The variable for the summary line is gnus-summary-format-line. I am not using the default value for this variable, but instead am using the value %U%R%z %(%&user-date; %-15,15f %* %B%s%)\n.
As described here, a new face can be applied to any (sub)section of a format line by bracketing the section with %1{ and %}, where the 1 in this example corresponds to gnus-face-1. gnus-face-1 in my installation defaults to "italics", so adding the following to my ~/.emacs file results in the author in the summary line appearing in italics:
(setq gnus-summary-line-format "%U%R%z %(%&user-date; %1{%-15,15f%} %* %B%s%)\n")
I go with M-x list-faces-display (which opens a new buffer with all the currently defined face variables fontified to the color that they're set to, in alphabetic order) when I want to see what faces I need to change to get a mode working.
Then I setq them, using either the format from color-theme or from the new emacs built-in theme format, depending on which version of emacs I'm in.