Sebastian P. Luque writes: > Thank you, Juan. Unfortunately, there is a price for this solution as > it is now impossible to name and refer to this segment as usual:
I see. Have you tried the option with LuaTeX that I put in my other message? You can compile with LuaTeX also using latexmk: (setq org-latex-pdf-process '("latexmk -lualatex -e '$lualatex=q/lualatex %%O -shell-escape %%S/' %f")) In any case, since this is a simple substitution, you can use also a function in Elisp as a final output filter[1]: #+BIND: org-export-filter-final-output-functions (caption-auto-width) #+begin_src emacs-lisp :exports results :results none (defun caption-auto-width (text backend info) (when (org-export-derived-backend-p backend 'latex) (with-temp-buffer (insert text) (save-excursion (goto-char (point-min)) (while (re-search-forward "\\(\\\\includegraphics.+\\)" nil t) (replace-match "\\\\sbox0{\\1}" t nil))) (save-excursion (goto-char (point-min)) (while (re-search-forward "\\(\\\\caption.+\\)" nil t) (replace-match "\\\\begin{minipage}{\\\\wd0}\\\\usebox0\\1\\\\end{minipage}" t nil))) (setq text (buffer-string))))) #+end_src Vid. [[fig:1]] #+NAME: fig:1 #+CAPTION: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus. Donec pretium posuere tellus #+ATTR_LaTeX: :width .3\linewidth [[my-image.jpg]] [1] You need to set this variable as non-nil, in order to use bind keywords: (setq org-export-allow-bind-keywords t) Hope this works, Best regards, Juan Manuel