emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Export LaTeX command inside figure environment
@ 2022-05-07 23:43 Thomas S. Dye
  2022-05-08  0:30 ` Juan Manuel Macías
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas S. Dye @ 2022-05-07 23:43 UTC (permalink / raw)
  To: emacs-org list

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Export LaTeX command inside figure environment
  2022-05-07 23:43 Export LaTeX command inside figure environment Thomas S. Dye
@ 2022-05-08  0:30 ` Juan Manuel Macías
  2022-05-08  0:57   ` Thomas S. Dye
  2022-05-08  5:08   ` Max Nikulin
  0 siblings, 2 replies; 7+ messages in thread
From: Juan Manuel Macías @ 2022-05-08  0:30 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: orgmode

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Export LaTeX command inside figure environment
  2022-05-08  0:30 ` Juan Manuel Macías
@ 2022-05-08  0:57   ` Thomas S. Dye
  2022-05-08  5:08   ` Max Nikulin
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas S. Dye @ 2022-05-08  0:57 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: Thomas S. Dye, orgmode

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Export LaTeX command inside figure environment
  2022-05-08  0:30 ` Juan Manuel Macías
  2022-05-08  0:57   ` Thomas S. Dye
@ 2022-05-08  5:08   ` Max Nikulin
  2022-05-08  6:06     ` Thomas S. Dye
  1 sibling, 1 reply; 7+ messages in thread
From: Max Nikulin @ 2022-05-08  5:08 UTC (permalink / raw)
  To: emacs-orgmode

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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Export LaTeX command inside figure environment
  2022-05-08  5:08   ` Max Nikulin
@ 2022-05-08  6:06     ` Thomas S. Dye
  2022-05-08 16:12       ` Juan Manuel Macías
  2022-05-08 16:35       ` Max Nikulin
  0 siblings, 2 replies; 7+ messages in thread
From: Thomas S. Dye @ 2022-05-08  6:06 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Export LaTeX command inside figure environment
  2022-05-08  6:06     ` Thomas S. Dye
@ 2022-05-08 16:12       ` Juan Manuel Macías
  2022-05-08 16:35       ` Max Nikulin
  1 sibling, 0 replies; 7+ messages in thread
From: Juan Manuel Macías @ 2022-05-08 16:12 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Maxim Nikulin, orgmode

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 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Export LaTeX command inside figure environment
  2022-05-08  6:06     ` Thomas S. Dye
  2022-05-08 16:12       ` Juan Manuel Macías
@ 2022-05-08 16:35       ` Max Nikulin
  1 sibling, 0 replies; 7+ messages in thread
From: Max Nikulin @ 2022-05-08 16:35 UTC (permalink / raw)
  To: emacs-orgmode

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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-08 16:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07 23:43 Export LaTeX command inside figure environment Thomas S. Dye
2022-05-08  0:30 ` Juan Manuel Macías
2022-05-08  0:57   ` Thomas S. Dye
2022-05-08  5:08   ` Max Nikulin
2022-05-08  6:06     ` Thomas S. Dye
2022-05-08 16:12       ` Juan Manuel Macías
2022-05-08 16:35       ` Max Nikulin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).