Aloha all, Is there a way to add an arbitrary LaTeX command between \begin{figure} ... \end{figure} during LaTeX export? I want to end up with the following snippet, but can't figure out how to slip in \setfloatalignment{b}. \begin{figure}[htb] \centering \includegraphics[width=.9\linewidth]{hilbertcurves.pdf} \caption[Hilbert curves]{\label{fig:orgparagraph1} Hilbert curves of various degrees \emph{n}.} \setfloatalignment{b} \end{figure} All the best, Tom -- Thomas S. Dye https://tsdye.online/tsdye
Hi, Thomas,
Thomas S. Dye writes:
> Is there a way to add an arbitrary LaTeX command between
> \begin{figure} ... \end{figure} during LaTeX export? I want to end up
> with the following snippet, but can't figure out how to slip in
> \setfloatalignment{b}. \begin{figure}[htb]
> \centering
> \includegraphics[width=.9\linewidth]{hilbertcurves.pdf}
> \caption[Hilbert curves]{\label{fig:orgparagraph1} Hilbert curves of
> various degrees \emph{n}.}
> \setfloatalignment{b}
> \end{figure}
I think the :caption attribute could do the trick (of course everything
must be on one line):
#+ATTR_LaTeX: :caption \caption[Hilbert
curves]{\label{fig:orgparagraph1} Hilbert curves of various degrees
\emph{n}.}\setfloatalignment{b}
Best regards,
Juan Manuel
Aloha Juan Manuel, Juan Manuel Macías <maciaschain@posteo.net> writes: > Hi, Thomas, > > Thomas S. Dye writes: > >> Is there a way to add an arbitrary LaTeX command between >> \begin{figure} ... \end{figure} during LaTeX export? I want to >> end up >> with the following snippet, but can't figure out how to slip in >> \setfloatalignment{b}. \begin{figure}[htb] >> \centering >> \includegraphics[width=.9\linewidth]{hilbertcurves.pdf} >> \caption[Hilbert curves]{\label{fig:orgparagraph1} Hilbert >> curves of >> various degrees \emph{n}.} >> \setfloatalignment{b} >> \end{figure} > > I think the :caption attribute could do the trick (of course > everything > must be on one line): > > #+ATTR_LaTeX: :caption \caption[Hilbert > curves]{\label{fig:orgparagraph1} Hilbert curves of various > degrees > \emph{n}.}\setfloatalignment{b} > That works. Thanks! All the best, Tom -- Thomas S. Dye https://tsdye.online/tsdye
On 08/05/2022 07:30, Juan Manuel Macías wrote:
> Thomas S. Dye writes:
>
>> Is there a way to add an arbitrary LaTeX command between
>> \begin{figure} ... \end{figure} during LaTeX export? I want to end up
>> with the following snippet, but can't figure out how to slip in
>> \setfloatalignment{b}. \begin{figure}[htb]
>> \centering
>> \includegraphics[width=.9\linewidth]{hilbertcurves.pdf}
>> \caption[Hilbert curves]{\label{fig:orgparagraph1} Hilbert curves of
>> various degrees \emph{n}.}
>> \setfloatalignment{b}
>> \end{figure}
>
> I think the :caption attribute could do the trick (of course everything
> must be on one line):
>
> #+ATTR_LaTeX: :caption \caption[Hilbert
> curves]{\label{fig:orgparagraph1} Hilbert curves of various degrees
> \emph{n}.}\setfloatalignment{b}
Would it work if \setfloatalignment{b} is added before \includegraphics?
From my point of view, it is still a hack due to abusing the :placement
attribute, but it is backend agnostic, so reuses caption for HTML and
relieves requirement of single long line:
#+caption[Hilbert curves]: Hilbert curves of various degrees \(n\)
#+name: orgparagraph1
#+attr_latex: :placement [b]\setfloatalignment{b}
[[file:hilbertcurves.pdf]]
# Local Variables:
# org-latex-prefer-user-labels: t
# End:
P.S. Math and absence of period are intentional. I never used tufte, so
unsure if something besides b is meaningful with \setfloatalignment{b}.
I dropped "ht" to make inconsistency apparent and expecting that when
figures are moved to the end of document, "ht" should be used instead
with removing of \setfloatalignment.
Aloha Max, Max Nikulin <manikulin@gmail.com> writes: > On 08/05/2022 07:30, Juan Manuel Macías wrote: >> Thomas S. Dye writes: >> >>> Is there a way to add an arbitrary LaTeX command between >>> \begin{figure} ... \end{figure} during LaTeX export? I want >>> to end up >>> with the following snippet, but can't figure out how to slip >>> in >>> \setfloatalignment{b}. \begin{figure}[htb] >>> \centering >>> \includegraphics[width=.9\linewidth]{hilbertcurves.pdf} >>> \caption[Hilbert curves]{\label{fig:orgparagraph1} Hilbert >>> curves of >>> various degrees \emph{n}.} >>> \setfloatalignment{b} >>> \end{figure} >> I think the :caption attribute could do the trick (of course >> everything >> must be on one line): >> #+ATTR_LaTeX: :caption \caption[Hilbert >> curves]{\label{fig:orgparagraph1} Hilbert curves of various >> degrees >> \emph{n}.}\setfloatalignment{b} > > Would it work if \setfloatalignment{b} is added before > \includegraphics? From > my point of view, it is still a hack due to abusing the > :placement attribute, > but it is backend agnostic, so reuses caption for HTML and > relieves requirement > of single long line: > > #+caption[Hilbert curves]: Hilbert curves of various degrees > \(n\) > #+name: orgparagraph1 > #+attr_latex: :placement [b]\setfloatalignment{b} > [[file:hilbertcurves.pdf]] > > # Local Variables: > # org-latex-prefer-user-labels: t > # End: > > P.S. Math and absence of period are intentional. I never used > tufte, so unsure > if something besides b is meaningful with \setfloatalignment{b}. > I dropped "ht" > to make inconsistency apparent and expecting that when figures > are moved to the > end of document, "ht" should be used instead with removing of > \setfloatalignment. Yes, this works, too. It is a convenient hack. Thanks! It would be better to have a LaTeX attribute, say :commands, that places commands within \begin{figure} ... \end{figure}. I'm circling back to Tufte handouts for a course I'm offering in the Fall. It is great that ox-latex has the flexibility to export to tufte-latex now. I haven't prepared any handouts yet, but all the pieces seem to work in a straightforward way. Org-cite is performing like a champ, too! All the best, Tom -- Thomas S. Dye https://tsdye.online/tsdye
Thomas S. Dye writes: > It would be better to have a LaTeX attribute, say :commands, that > places commands within \begin{figure} ... \end{figure}. This is a possible solution from the LaTeX side, which would avoid having to modify the Org code and can also be used to introduce more complex arbitrary code into the figure environment. It consists of defining a variable (for arbitrary code) and redefining the figure environment to include that variable. Something like this: #+NAME: preamble #+begin_src latex :exports none \usepackage{graphicx,xparse} \def\myfigcode#1{#1} \let\svfigure\figure \let\endsvfigure\endfigure \DeclareDocumentEnvironment{figure}{o}{% \IfNoValueTF{#1}{% \begin{svfigure}} {\begin{svfigure}[#1]} \myfigcode% } {\end{svfigure}} #+end_src #+begin_src latex :noweb yes :results raw ,#+LaTeX_HEADER: <<preamble>> #+end_src Here I use the dummy images from the graphicx package. Of course, then it is necessary to apply a zero value to the variable again, or enclose all in a \begingroup...\endgroup. It's a bit tricky and I haven't tried it too much: @@latex:\begingroup\def\myfigcode{{\centering\fbox{\textbf{Hello world!!!}}\par\vspace{5ex}}}@@ #+caption: This is a caption #+ATTR_LaTeX: :placement [h] :width .5\linewidth [[file:example-image-a.jpg]] @@latex:\endgroup@@ #+caption: This is a caption #+ATTR_LaTeX: :placement [h] :width .5\linewidth [[file:example-image-b.jpg]] A screenshot: https://i.imgur.com/8JIU6nX.png Best regards, Juan Manuel
On 08/05/2022 13:06, Thomas S. Dye wrote:
>
> It would be better to have a LaTeX attribute, say :commands, that places
> commands within \begin{figure} ... \end{figure}.
Look at the code of `org-latex--inline-image' and variants of markup it
may generate. There are too may places where :commands may be inserted
to add an attribute for each place, e.g. before or after
\includegraphics. It may be better to allow users to define a function
that either generates markup or delegates it to the default function. I
am unsure concerning convenient API that should be provided to generate
a label, to get caption that may be specified as an attribute or as
#+caption:, etc. There is a quite similar problem with source blocks
(another thread). 10 arguments functions emerged during attempt split
into maintainable pieces a huge function handling all cases.