emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: Seb <spluque@gmail.com>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: caption width in LateX export
Date: Mon, 27 Dec 2021 09:09:16 +0000	[thread overview]
Message-ID: <87y246s9c3.fsf@posteo.net> (raw)
In-Reply-To: <874k6utry0.fsf@posteo.net> ("Juan Manuel =?utf-8?Q?Mac=C3=AD?= =?utf-8?Q?as=22's?= message of "Mon, 27 Dec 2021 07:41:59 +0000")

P.S.: I have come up with another possibility, more automatic, on the
LaTeX side, if you compile with LuaTeX. This thread
where someone proposes to use a \savebox for concrete images, gave me
the idea. We can automate that through a simple function in Lua, and add
it to the `process_input_buffer' callback, in order to the caption
*always* has the width of each image:

You can put this in your Org document:

#+NAME: luacode
#+begin_src latex :exports none

  function caption_width ( text )
  text = string.gsub ( text, "(\\includegraphics.+)", "\\sbox0{%1}")
  text = string.gsub ( text, "(\\caption{.+})", "\\begin{minipage}{\\wd0}\\usebox0%1\\end{minipage}")
  return text

( "process_input_buffer" , caption_width , "caption_width" )}}


#+begin_src latex :noweb yes :results raw
,#+LaTeX_HEADER: <<luacode>>

And then:

#+CAPTION: Lorem ipsum dolor sit amet, consectetuer adipiscing elit
#+ATTR_LaTeX: :width .3\linewidth

Best regards,

Juan Manuel 

Juan Manuel Macías writes:

> If you use the caption package (https://www.ctan.org/pkg/caption), you
> can indicate in each figure the width of the caption. In this case, you
> would have to introduce the code using raw latex via the `:caption'
> property:
> #+LaTeX_Header: \usepackage{caption}
> #+ATTR_LaTeX: :caption \captionsetup{width=.3\linewidth}\caption{Lorem ipsum dolor sit amet, consectetuer adipiscing elit}
> #+ATTR_LaTeX: :width .3\linewidth
> [[file_path]]

  reply	other threads:[~2021-12-27  9:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-27  1:22 Seb
2021-12-27  7:41 ` Juan Manuel Macías
2021-12-27  9:09   ` Juan Manuel Macías [this message]
2021-12-27 12:53   ` Sebastian P. Luque
2021-12-27 13:28     ` Juan Manuel Macías
2021-12-27 17:16       ` Sebastian P. Luque
2021-12-27 19:28         ` Juan Manuel Macías
2021-12-28 14:58 ` Eric S Fraga
2021-12-28 15:59   ` Seb
2021-12-28 16:26     ` 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:

  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=87y246s9c3.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=spluque@gmail.com \
    --subject='Re: caption width in LateX export' \


* 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:


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).