This answer of question Bookmark tables and figures says

[usage of \bookmark ready to be inserted]

Next issue: \caption often sets its argument twice, because it wants to check, whether the caption fits in one line. This can be turned off with singlelinecheck=false. But this affects the formatting of single line captions.

[first solution, using \DeclareCaptionTextFormat to define a new caption text format in which an \bookmark is inserted]


I am curious about what happens when "\caption sets its argument twice", so I use a simplified example and come with the following table:

| Engine + format | is `caption` loaded | is bookmark duplicate             |
| --------------- | ------------------- | --------------------------------- |
| xelatex         | no                  | no                                |
| xelatex         | yes                 | no                                |
| pdflatex        | no                  | only multiline captions duplicate |
| pdflatex        | yes                 | yes                               |

Here "duplicate" means there are two adjacent bookmarks, both having the same content and destination, in the PDF file.

  • no duplicate: no duplicate
  • partly duplicate: partly duplicate
  • fully duplicate: fully duplicate

Hence my question is

  1. Why the output is engine dependent?
    I guess this may come from the different bookmark driver files, but currently I am not able to read through or understand them.
    From another perspective, if every usage of \caption sets its argument twice (for example, inside \@makecaption provided by standard classes), bookmarks will always be duplicate, independent of engines.
  2. For pdflatex, why the output is pacakge caption dependent? Which part of the source code of this package causes this?

version info

  • macOS 12.14.2 with TeX Live 2018
  • XeTeX, 3.14159265-2.6-0.99999
  • pdfTeX, 3.14159265-2.6-1.40.19
  • LaTeX2e, 2018-12-01

output of \listfiles with caption loaded and xelatex

 *File List*
 article.cls    2018/09/03 v1.4i Standard LaTeX document class
  size10.clo    2018/09/03 v1.4i Standard LaTeX file (size option)
 caption.sty    2018/10/06 v3.3-154 Customizing captions (AR)
caption3.sty    2018/09/12 v1.8c caption3 kernel (AR)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
bookmark.sty    2016/05/17 v1.26 PDF bookmarks (HO)
pdfescape.sty    2016/05/16 v1.14 Implements pdfTeX's escape features (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
pdftexcmds.sty    2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO)
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
   ifpdf.sty    2018/09/07 v3.3 Provides the ifpdf switch
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
  ifvtex.sty    2016/05/16 v1.6 Detect VTeX and its facilities (HO)
hyperref.sty    2018/11/30 v6.88e Hypertext links for LaTeX
hobsub-hyperref.sty    2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO)
hobsub-generic.sty    2016/05/16 v1.14 Bundle oberdiek, subset generic (HO)
  hobsub.sty    2016/05/16 v1.14 Construct package bundles (HO)
 intcalc.sty    2016/05/16 v1.2 Expandable calculations with integers (HO)
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
kvdefinekeys.sty    2016/05/16 v1.4 Define keys (HO)
bigintcalc.sty    2016/05/16 v1.4 Expandable calculations on big integers (HO)
  bitset.sty    2016/05/16 v1.2 Handle bit-vector datatype (HO)
uniquecounter.sty    2016/05/16 v1.3 Provide unlimited unique counter (HO)
letltxmacro.sty    2016/05/16 v1.5 Let assignment for LaTeX macros (HO)
 hopatch.sty    2016/05/16 v1.3 Wrapper for package hooks (HO)
xcolor-patch.sty    2016/05/16 xcolor patch
atveryend.sty    2016/05/16 v1.9 Hooks at the very end of document (HO)
atbegshi.sty    2016/06/09 v1.18 At begin shipout hook (HO)
refcount.sty    2016/05/16 v3.5 Data extraction from label references (HO)
 hycolor.sty    2016/05/16 v1.8 Color options for hyperref/bookmark (HO)
 auxhook.sty    2016/05/16 v1.4 Hooks for auxiliary files (HO)
kvoptions.sty    2016/05/16 v3.12 Key value format for package options (HO)
  pd1enc.def    2018/11/30 v6.88e Hyperref: PDFDocEncoding definition (HO)
hyperref.cfg    2002/06/06 v1.2 hyperref configuration of TeXLive
     url.sty    2013/09/16  ver 3.4  Verb mode for urls, etc.
  hxetex.def    2018/11/30 v6.88e Hyperref driver for XeTeX
   puenc.def    2018/11/30 v6.88e Hyperref: PDF Unicode definition (HO)
stringenc.sty    2016/05/16 v1.11 Convert strings between diff. encodings (HO)
rerunfilecheck.sty    2016/05/16 v1.8 Rerun checks for auxiliary files (HO)
bkm-dvipdfm.def    2016/05/17 v1.26 bookmark driver for dvipdfm (HO)
 nameref.sty    2016/05/21 v2.44 Cross-referencing by name of section
gettitlestring.sty    2016/05/16 v1.5 Cleanup title references (HO)
se-ascii-print.def    2016/05/16 v1.11 stringenc: Printable ASCII characters

Example document

% simplified from https://tex.stackexchange.com/a/178548/79060
  \bookmark[dest=\@currentHref]{Figure \thefigure: #1}%


dummy text
 \caption{\addBookmark{Figure caption text}}

 \caption{\addBookmark{Figure caption long long long long long long long long long long long long text}}

\newpage % add a blank page to make it easier to see bookmark targets
dummy text


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.