From: "Juan Manuel Macías" <maciaschain@posteo.net> To: orgmode <emacs-orgmode@gnu.org> Subject: [tip] Insert arbitrary LaTeX code at the beginning of any float environment Date: Sun, 08 May 2022 22:22:16 +0000 [thread overview] Message-ID: <87o807r7fr.fsf@posteo.net> (raw) 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
next reply other threads:[~2022-05-08 22:23 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-08 22:22 Juan Manuel Macías [this message] 2022-05-09 12:47 ` Ihor Radchenko 2022-05-09 13:15 ` Eric S Fraga 2022-05-09 13:51 ` Ihor Radchenko 2022-05-09 14:01 ` Juan Manuel Macías 2022-05-09 14:14 ` Eric S Fraga
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://www.orgmode.org/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=87o807r7fr.fsf@posteo.net \ --to=maciaschain@posteo.net \ --cc=emacs-orgmode@gnu.org \ --subject='Re: [tip] Insert arbitrary LaTeX code at the beginning of any float environment' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this 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).