Hi all, If we want to introduce arbitrary LaTeX code at the very beginning of a float environment, apart from the usual tricks of putting the code in :caption or :placement, this solution I describe here is more from the LaTeX side. I thik its advantages are more control and consistency from the point of view of LaTeX, and the possibility of introducing code of a certain complexity. Well, you have to write some LaTeX code for the preamble, but it's really not much :) We have to define a global command \myenvcode{<arbitrary code>} (if we want to add the code to all document floats environments), and also a 'Myenvcode' environment, with the same argument. The etoolbox LaTeX package provides a number of hooks: \AtBeginEnvironment, \AtEndEnvironment, etc., but if we want our arbitrary code to be at the very beginning of the environment, it's safer to use the \@floatboxreset hook. So, the code that we would have to add to our preamble would be (I prefer to define the command and environment using the xparse syntax): #+NAME: preamble #+begin_src latex :exports none \usepackage{xparse} \makeatletter \def\my@envcode{} \NewDocumentCommand{\myenvcode}{+m}{% \def\my@envcode{#1}} \g@addto@macro\@floatboxreset{\my@envcode} \makeatother \NewDocumentEnvironment{Myenvcode}{+m}{% \IfNoValueF{#1}{\myenvcode{#1}}} {\par} #+end_src #+begin_src latex :noweb yes :results raw ,#+LaTeX_HEADER: <<preamble>> #+end_src And here a few examples: #+ATTR_LaTeX: :options {\centering\fbox{Code before a image}\par\vspace{1ex}} #+begin_Myenvcode #+CAPTION: This is a image #+ATTR_LaTeX: :width .5\linewidth :placement [h] [[file:example-image-a.jpg]] #+end_Myenvcode #+ATTR_LaTeX: :options {\captionsetup{font={color=red}}} #+begin_Myenvcode #+CAPTION: This is a image #+ATTR_LaTeX: :width .5\linewidth :placement [h] [[file:example-image-b.jpg]] #+end_Myenvcode #+latex: \myenvcode{{\centering\fbox{Code before a table}\par\vspace{1ex}}} #+CAPTION: This is a table #+ATTR_LaTeX: :placement [h] :booktabs t | a | b | c | d | f | |---+---+---+---+---| | 1 | 2 | 3 | 4 | 5 | #+latex: \myenvcode{} Best regards, Juan Manuel
Juan Manuel Macías <maciaschain@posteo.net> writes:
> If we want to introduce arbitrary LaTeX code at the very beginning of a
> float environment, apart from the usual tricks of putting the code in
> :caption or :placement, this solution I describe here is more from the
> LaTeX side. I thik its advantages are more control and consistency from
> the point of view of LaTeX, and the possibility of introducing code of a
> certain complexity.
I'd be happy to see a built-in solution for this.
I feel that the ability to insert arbitrary LaTeX code near the
begin/end of environment would be generally a useful feature to have in
ox-latex. It could be done via #+attr_latex: :pre/:post
Moreover, it would be useful to be able to wrap the whole chunk into
custom environment:
#+attr_latex: :wrap [options]environmant
WDYT?
Best,
Ihor
On Monday, 9 May 2022 at 20:47, Ihor Radchenko wrote:
> Moreover, it would be useful to be able to wrap the whole chunk into
> custom environment:
> #+attr_latex: :wrap [options]environmant
This is already possible using special blocks? I.e.
#+begin_environment
... figure stuff
#+end_environment
unless you mean something different.
--
: Eric S Fraga, with org release_9.5.3-478-g2a6f5c in Emacs 29.0.50
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> On Monday, 9 May 2022 at 20:47, Ihor Radchenko wrote:
>> Moreover, it would be useful to be able to wrap the whole chunk into
>> custom environment:
>> #+attr_latex: :wrap [options]environmant
>
> This is already possible using special blocks? I.e.
>
> #+begin_environment
> ... figure stuff
> #+end_environment
>
> unless you mean something different.
Nope. I meant exactly this. Time to re-read the manual again :)
Best,
Ihor
Ihor Radchenko writes:
> I'd be happy to see a built-in solution for this.
> I feel that the ability to insert arbitrary LaTeX code near the
> begin/end of environment would be generally a useful feature to have in
> ox-latex. It could be done via #+attr_latex: :pre/:post
>
> Moreover, it would be useful to be able to wrap the whole chunk into
> custom environment:
> #+attr_latex: :wrap [options]environmant
>
> WDYT?
I think they are both great ideas, especially the second one. Although
---as Eric says--- we can always use special blocks, a :wrap attribute
would drastically lighten the readability of the document, and could be
very useful in those complex constructions where we need to enclose a
table or a figure in another environment (for example, with the
threeparttable package and others like it).
Best regards,
Juan Manuel
On Monday, 9 May 2022 at 14:01, Juan Manuel Macías wrote:
> Although ---as Eric says--- we can always use special blocks, a :wrap
> attribute would drastically lighten the readability of the document,
One advantage of special blocks is that they work across all
(some/most/?) export backends and are not tied to LaTeX.
--
: Eric S Fraga, with org release_9.5.3-478-g2a6f5c in Emacs 29.0.50