| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3graphics.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2017-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3kernel bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/latex3 |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\documentclass[full]{l3doc} |
| 27 |
\begin{document} |
| 28 |
\DocInput{\jobname.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% \fi |
| 32 |
% |
| 33 |
% \title{^^A |
| 34 |
% The \pkg{l3graphics} module\\ Graphics inclusion support^^A |
| 35 |
% } |
| 36 |
% |
| 37 |
% \author{^^A |
| 38 |
% The \LaTeX{} Project\thanks |
| 39 |
% {^^A |
| 40 |
% E-mail: |
| 41 |
% \href{mailto:[email protected]} |
| 42 |
% {[email protected]}^^A |
| 43 |
% }^^A |
| 44 |
% } |
| 45 |
% |
| 46 |
% \date{Released 2026-05-15} |
| 47 |
% |
| 48 |
% \maketitle |
| 49 |
% |
| 50 |
% \begin{documentation} |
| 51 |
% |
| 52 |
% \section{Graphics keys} |
| 53 |
% |
| 54 |
% Inclusion of graphic files requires a range of low-level data be passed to |
| 55 |
% the backend. This is set up using a small number of key--value settings, |
| 56 |
% which are stored in the |graphics| tree. |
| 57 |
% |
| 58 |
% \begin{variable}{decodearray} |
| 59 |
% Array to decode color in bitmap graphic: when non-empty, this should |
| 60 |
% be in the form of one, two or three pairs of real numbers in the range |
| 61 |
% $[0,1]$, separated by spaces. |
| 62 |
% \end{variable} |
| 63 |
% |
| 64 |
% \begin{variable}{draft} |
| 65 |
% Switch to enable draft mode: graphics are read but not included when this is |
| 66 |
% true. |
| 67 |
% \end{variable} |
| 68 |
% |
| 69 |
% \begin{variable}{interpolate} |
| 70 |
% Switch which indicates whether interpolation should be applied to bitmap |
| 71 |
% graphic files. |
| 72 |
% \end{variable} |
| 73 |
% |
| 74 |
% \begin{variable}{page} |
| 75 |
% The page to extract from a multi-page graphic file: used for |.pdf| files |
| 76 |
% which may contain multiple pages. |
| 77 |
% \end{variable} |
| 78 |
% |
| 79 |
% \begin{variable}{pdf-attr} |
| 80 |
% Additional PDF-focussed attributes: available to allow control of |
| 81 |
% extended |.pdf| structures beyond those needed for graphic inclusion. |
| 82 |
% Due to backend restrictions, this key is only functional with direct |
| 83 |
% PDF mode (pdf\TeX{} and Lua\TeX{}). |
| 84 |
% \end{variable} |
| 85 |
% |
| 86 |
% \begin{variable}{pagebox} |
| 87 |
% The nature of the page box setting used to determine the bounding box of |
| 88 |
% material: used for |.pdf| files which feature multiple page box |
| 89 |
% specifications. A choice from |art|, |bleed|, |crop|, |media|, |trim|. |
| 90 |
% The standard setting is |crop|. |
| 91 |
% \end{variable} |
| 92 |
% |
| 93 |
% \begin{variable}{type} |
| 94 |
% The type of graphic file being included: if this key is not set, the |
| 95 |
% \emph{type} is determined from the file extension. |
| 96 |
% \end{variable} |
| 97 |
% |
| 98 |
% \section{Including graphics} |
| 99 |
% |
| 100 |
% \begin{function}[added = 2025-03-14] |
| 101 |
% {\graphics_include:nn, \graphics_include:nV} |
| 102 |
% \begin{syntax} |
| 103 |
% \cs{graphics_include:nn} \Arg{keys} \Arg{file} |
| 104 |
% \end{syntax} |
| 105 |
% Horizontal-mode command which includes the \meta{file} as a graphic |
| 106 |
% at the current location. The file \meta{type} may be given as one of the |
| 107 |
% \meta{keys}, or will otherwise be determined from file extension. The |
| 108 |
% \meta{keys} is used to pass settings as detailed above. |
| 109 |
% \end{function} |
| 110 |
% |
| 111 |
% \begin{variable}[added = 2025-03-14]{\l_graphics_ext_type_prop} |
| 112 |
% Defines mapping between file extensions and file types; where there is |
| 113 |
% no entry for an extension, the type is assumed to be the extension |
| 114 |
% with the leading |.| removed. Entries should be made in lower case, and |
| 115 |
% the key should be an extension including the leading |.|, for example |
| 116 |
% \begin{verbatim} |
| 117 |
% \prop_put:Nnn \l_graphics_ext_type_prop { .ps } { eps } |
| 118 |
% \end{verbatim} |
| 119 |
% \end{variable} |
| 120 |
% |
| 121 |
% \begin{variable}[added = 2025-03-14]{\l_graphics_search_ext_seq} |
| 122 |
% Extensions to use for graphic searching when the given \meta{file} name is not |
| 123 |
% found by \cs{graphics_get_full_name:nN}. |
| 124 |
% \end{variable} |
| 125 |
% |
| 126 |
% \begin{variable}[added = 2025-03-14]{\l_graphics_search_path_seq} |
| 127 |
% Each entry is the path to a directory which should be searched when |
| 128 |
% seeking a graphic file. Each path can be relative or absolute, and should |
| 129 |
% not include the trailing slash. The entries are not expanded when |
| 130 |
% used so may contain active characters but should not feature any |
| 131 |
% variable content. Spaces need not be quoted. |
| 132 |
% \end{variable} |
| 133 |
% |
| 134 |
% \section{Utility functions} |
| 135 |
% |
| 136 |
% \begin{function}[noTF, added = 2025-03-14]{\graphics_get_full_name:nN} |
| 137 |
% \begin{syntax} |
| 138 |
% \cs{graphics_get_full_name:nN} \Arg{file} \meta{tl~var} |
| 139 |
% \cs{graphics_get_full_name:nNTF} \Arg{file} \meta{tl~var} \Arg{true code} \Arg{false code} |
| 140 |
% \end{syntax} |
| 141 |
% Searches for \meta{file} first as given and then using the extensions |
| 142 |
% listed in \cs{l_graphics_search_ext_seq}. The search path used will be |
| 143 |
% the entries of \cs{l_graphics_search_path_seq}. If found, the full file |
| 144 |
% name including any path and extension will be returned in the |
| 145 |
% \meta{tl~var}. In the non-branching version, the \meta{tl var} will be |
| 146 |
% set to \cs{q_no_value} in the case that the graphics is not found. |
| 147 |
% \end{function} |
| 148 |
% |
| 149 |
% \begin{function}[added = 2025-03-14]{\graphics_get_pagecount:nN} |
| 150 |
% \begin{syntax} |
| 151 |
% \cs{graphics_get_pagecount:nn} \Arg{file} \meta{tl~var} |
| 152 |
% \end{syntax} |
| 153 |
% Reads the graphics \meta{file} and extracts the number of pages, which |
| 154 |
% are stored in the \meta{tl~var}. |
| 155 |
% \end{function} |
| 156 |
% |
| 157 |
% \section{Showing and logging included graphics} |
| 158 |
% |
| 159 |
% \begin{function}[added = 2025-03-14] |
| 160 |
% {\graphics_show_list:, \graphics_log_list:} |
| 161 |
% \begin{syntax} |
| 162 |
% \cs{graphics_show_list:} |
| 163 |
% \cs{graphics_log_list:} |
| 164 |
% \end{syntax} |
| 165 |
% These functions list all graphic files loaded in a similar manner to |
| 166 |
% \cs{file_show_list:} and \cs{file_log_list:}. While |
| 167 |
% \cs{graphics_show_list:} displays the list in the terminal, |
| 168 |
% \cs{graphics_log_list:} outputs it to the log file only. In both cases, only |
| 169 |
% graphics loaded by \pkg{l3graphics} are listed. |
| 170 |
% \end{function} |
| 171 |
% |
| 172 |
% \end{documentation} |
| 173 |
% |
| 174 |
% \begin{implementation} |
| 175 |
% |
| 176 |
% \section{\pkg{l3graphics} implementation} |
| 177 |
% |
| 178 |
% \begin{macrocode} |
| 179 |
%<*code> |
| 180 |
% \end{macrocode} |
| 181 |
% |
| 182 |
% \begin{macrocode} |
| 183 |
%<@@=graphics> |
| 184 |
% \end{macrocode} |
| 185 |
% |
| 186 |
% \begin{variable}{\l_@@_tmp_dim, \l_@@_tmp_ior, \l_@@_tmp_tl} |
| 187 |
% Scratch space. |
| 188 |
% \begin{macrocode} |
| 189 |
\dim_new:N \l_@@_tmp_dim |
| 190 |
\ior_new:N \l_@@_tmp_ior |
| 191 |
\tl_new:N \l_@@_tmp_tl |
| 192 |
% \end{macrocode} |
| 193 |
% \end{variable} |
| 194 |
% |
| 195 |
% \begin{variable}{\s_@@_stop} |
| 196 |
% Internal scan marks. |
| 197 |
% \begin{macrocode} |
| 198 |
\scan_new:N \s_@@_stop |
| 199 |
% \end{macrocode} |
| 200 |
% \end{variable} |
| 201 |
% |
| 202 |
% \subsection{Graphics keys} |
| 203 |
% |
| 204 |
% \begin{macro} |
| 205 |
% { |
| 206 |
% \l_@@_decodearray_str , |
| 207 |
% \l__@@_draft_bool , |
| 208 |
% \l_@@_interpolate_bool , |
| 209 |
% \l_@@_page_int , |
| 210 |
% \l_@@_pagebox_tl , |
| 211 |
% \l_@@_pdf_str , |
| 212 |
% \l_@@_type_str |
| 213 |
% } |
| 214 |
% Keys which control features of graphics. The standard value of |pagebox| |
| 215 |
% set up here should match the default for the backends themselves: in |
| 216 |
% the absence of any other setting the |crop| should be used. Note that |
| 217 |
% the variable \cs{l_@@_pagebox_str} can be empty internally, as backends |
| 218 |
% which do not support |pagebox| are set up to clear it entirely. The |
| 219 |
% store for |pagebox| is a |tl| as that makes extracting the data |
| 220 |
% easier for some backends. |
| 221 |
% \begin{macrocode} |
| 222 |
\tl_new:N \l_@@_pagebox_tl |
| 223 |
\keys_define:nn { graphics } |
| 224 |
{ |
| 225 |
decodearray .str_set:N = |
| 226 |
\l_@@_decodearray_str , |
| 227 |
draft .bool_set:N = |
| 228 |
\l_@@_draft_bool , |
| 229 |
interpolate .bool_set:N = |
| 230 |
\l_@@_interpolate_bool , |
| 231 |
pagebox .choices:nn = |
| 232 |
{ art , bleed , crop , media , trim } |
| 233 |
{ |
| 234 |
\tl_set:Ne \l_@@_pagebox_tl |
| 235 |
{ \l_keys_choice_tl box } |
| 236 |
} , |
| 237 |
pagebox .initial:n = |
| 238 |
crop , |
| 239 |
page .int_set:N = |
| 240 |
\l_@@_page_int , |
| 241 |
pdf-attr .str_set:N = |
| 242 |
\l_@@_pdf_str , |
| 243 |
type .str_set:N = |
| 244 |
\l_@@_type_str |
| 245 |
} |
| 246 |
% \end{macrocode} |
| 247 |
% \end{macro} |
| 248 |
% |
| 249 |
% \subsection{Obtaining bounding box data} |
| 250 |
% |
| 251 |
% \begin{variable} |
| 252 |
% { |
| 253 |
% \l_@@_llx_dim , \l_@@_lly_dim, |
| 254 |
% \l_@@_urx_dim , \l_@@_ury_dim |
| 255 |
% } |
| 256 |
% Storage for the return of bounding box. |
| 257 |
% \begin{macrocode} |
| 258 |
\dim_new:N \l_@@_llx_dim |
| 259 |
\dim_new:N \l_@@_lly_dim |
| 260 |
\dim_new:N \l_@@_urx_dim |
| 261 |
\dim_new:N \l_@@_ury_dim |
| 262 |
% \end{macrocode} |
| 263 |
% \end{variable} |
| 264 |
% |
| 265 |
% \begin{macro}{\@@_bb_save:n, \@@_bb_save:e} |
| 266 |
% \begin{macro}{\@@_bb_restore:nF, \@@_bb_restore:eF} |
| 267 |
% Caching graphic bounding boxes is sensible, and these functions are needed both |
| 268 |
% here and for drive-specific work. So they are made available as documented |
| 269 |
% functions. To save on registers, the \enquote{origin} is only saved if it is |
| 270 |
% not at zero. |
| 271 |
% \begin{macrocode} |
| 272 |
\cs_new_protected:Npn \@@_bb_save:n #1 |
| 273 |
{ |
| 274 |
\dim_if_exist:cTF { c_@@_ #1 _urx_dim } |
| 275 |
{ \msg_error:nnn { graphic } { bb-already-cached } {#1} } |
| 276 |
{ |
| 277 |
\dim_compare:nNnF \l_@@_llx_dim = { 0pt } |
| 278 |
{ \dim_const:cn { c_@@_ #1 _llx_dim } { \l_@@_llx_dim } } |
| 279 |
\dim_compare:nNnF \l_@@_lly_dim = { 0pt } |
| 280 |
{ \dim_const:cn { c_@@_ #1 _lly_dim } { \l_@@_lly_dim } } |
| 281 |
\dim_const:cn { c_@@_ #1 _urx_dim } { \l_@@_urx_dim } |
| 282 |
\dim_const:cn { c_@@_ #1 _ury_dim } { \l_@@_ury_dim } |
| 283 |
} |
| 284 |
} |
| 285 |
\cs_generate_variant:Nn \@@_bb_save:n { e } |
| 286 |
\cs_new_protected:Npn \@@_bb_restore:nF #1#2 |
| 287 |
{ |
| 288 |
\dim_if_exist:cTF { c_@@_ #1 _urx_dim } |
| 289 |
{ |
| 290 |
\dim_set_eq:Nc \l_@@_urx_dim { c_@@_ #1 _urx_dim } |
| 291 |
\dim_set_eq:Nc \l_@@_ury_dim { c_@@_ #1 _ury_dim } |
| 292 |
\dim_if_exist:cTF { c_@@_ #1 _llx_dim } |
| 293 |
{ \dim_set_eq:Nc \l_@@_llx_dim { c_@@_ #1 _llx_dim } } |
| 294 |
{ \dim_zero:N \l_@@_llx_dim } |
| 295 |
\dim_if_exist:cTF { c_@@_ #1 _lly_dim } |
| 296 |
{ \dim_set_eq:Nc \l_@@_lly_dim { c_@@_ #1 _lly_dim } } |
| 297 |
{ \dim_zero:N \l_@@_lly_dim } |
| 298 |
} |
| 299 |
{#2} |
| 300 |
} |
| 301 |
\cs_generate_variant:Nn \@@_bb_restore:nF { e } |
| 302 |
% \end{macrocode} |
| 303 |
% \end{macro} |
| 304 |
% \end{macro} |
| 305 |
% |
| 306 |
% \begin{macro}{\@@_extract_bb:n, \@@_read_bb:n} |
| 307 |
% \begin{macro}{\@@_extract_bb_auix:nn, \@@_extract_bb_auix:Vn} |
| 308 |
% \begin{macro}{\@@_extract_bb_auxii:nnn} |
| 309 |
% \begin{macro}{\@@_extract_bb_auxiii:nnnn, \@@_extract_bb_auxiii:Vnnn} |
| 310 |
% \begin{macro}{\@@_extract_bb_auxiv:nnn} |
| 311 |
% \begin{macro}{\@@_read_bb_auxi:nnnn, \@@_read_bb_auxii:Vnnn} |
| 312 |
% \begin{macro} |
| 313 |
% { |
| 314 |
% \@@_read_bb_auxii:w , |
| 315 |
% \@@_read_bb_auxiv:w , |
| 316 |
% \@@_read_bb_auxv:w |
| 317 |
% } |
| 318 |
% Extracting the bounding box from an |.eps| or |.bb| file is done by |
| 319 |
% reading each line and searching for the marker text |%%BoundingBox:|. |
| 320 |
% The data is read as a string with a mapping over |
| 321 |
% the lines: as there is a colon involved, a little bit of work is needed to |
| 322 |
% get the matching correct. The same approach covers cases where the bounding |
| 323 |
% box has to be calculated by |extractbb|, with just the initial phase |
| 324 |
% different. |
| 325 |
% \begin{macrocode} |
| 326 |
\cs_new_protected:Npn \@@_extract_bb:n #1 |
| 327 |
{ |
| 328 |
\int_compare:nNnTF \l_@@_page_int > 0 |
| 329 |
{ \@@_extract_bb_auxi:Vn \l_@@_page_int {#1} } |
| 330 |
{ \@@_extract_bb_auxii:nnn {#1} { } { } } |
| 331 |
} |
| 332 |
\cs_new_protected:Npn \@@_extract_bb_auxi:nn #1#2 |
| 333 |
{ \@@_extract_bb_auxii:nnn {#2} { :P #1 } { -p~#1~ } } |
| 334 |
\cs_generate_variant:Nn \@@_extract_bb_auxi:nn { Vn } |
| 335 |
\cs_new_protected:Npn \@@_extract_bb_auxii:nnn #1#2#3 |
| 336 |
{ |
| 337 |
\tl_if_empty:NTF \l_@@_pagebox_tl |
| 338 |
{ \@@_extract_bb_auxiv:nnn } |
| 339 |
{ \@@_extract_bb_auxiii:Vnnn \l_@@_pagebox_tl } |
| 340 |
{#1} {#2} {#3} |
| 341 |
} |
| 342 |
\cs_new_protected:Npn \@@_extract_bb_auxiii:nnnn #1#2#3#4 |
| 343 |
{ \@@_extract_bb_auxiv:nnn {#2} { : #1 #3 } { #4 -B~#1~ } } |
| 344 |
\cs_generate_variant:Nn \@@_extract_bb_auxiii:nnnn { V } |
| 345 |
\cs_new_protected:Npn \@@_extract_bb_auxiv:nnn #1#2#3 |
| 346 |
{ |
| 347 |
\@@_read_bb_auxi:nnnn {#1} {#2} |
| 348 |
{ \ior_shell_open:Nn \l_@@_tmp_ior { extractbb~#3-O~#1 } } |
| 349 |
{ pipe-failed } |
| 350 |
} |
| 351 |
\cs_new_protected:Npn \@@_read_bb:n #1 |
| 352 |
{ |
| 353 |
\@@_read_bb_auxi:nnnn {#1} { } |
| 354 |
{ \ior_open:Nn \l_@@_tmp_ior {#1} } |
| 355 |
{ graphic-not-found } |
| 356 |
} |
| 357 |
% \end{macrocode} |
| 358 |
% Before any real searching, a check to see if there are cached values |
| 359 |
% available. The name of each graphic will be unique and so it's sensible to |
| 360 |
% store the bounding box data in \TeX{}: this avoids multiple file operations. |
| 361 |
% As bounding boxes here start away from the lower-left origin, we need to |
| 362 |
% store all four values (contrast with for example the \texttt{pdfmode} |
| 363 |
% driver). Here |#2| is a potential page identifier: used to allow caching of |
| 364 |
% individual pages in a multi-page document. Caching is applied to the |
| 365 |
% upper-right position in all cases, but as the lower-left will often be |
| 366 |
% $(0,0)$ it is only cached if required. |
| 367 |
% \begin{macrocode} |
| 368 |
\cs_new_protected:Npn \@@_read_bb_auxi:nnnn #1#2#3#4 |
| 369 |
{ |
| 370 |
\@@_bb_restore:nF {#1#2} |
| 371 |
{ \@@_read_bb_auxii:nnnn {#3} {#4} {#1} {#2} } |
| 372 |
} |
| 373 |
\cs_new_protected:Npe \@@_read_bb_auxii:nnnn #1#2#3#4 |
| 374 |
{ |
| 375 |
#1 |
| 376 |
\exp_not:N \ior_if_eof:NTF \exp_not:N \l_@@_tmp_ior |
| 377 |
{ \msg_error:nnn { graphics } {#2} {#3} } |
| 378 |
{ |
| 379 |
\ior_str_map_inline:Nn \exp_not:N \l_@@_tmp_ior |
| 380 |
{ |
| 381 |
\exp_not:N \@@_read_bb_auxiii:w |
| 382 |
##1 ~ \c_colon_str \s_@@_stop |
| 383 |
} |
| 384 |
\@@_bb_save:n {#3#4} |
| 385 |
} |
| 386 |
\ior_close:N \exp_not:N \l_@@_tmp_ior |
| 387 |
} |
| 388 |
\use:e |
| 389 |
{ |
| 390 |
\cs_new_protected:Npn \exp_not:N \@@_read_bb_auxiii:w |
| 391 |
#1 \c_colon_str #2 \s_@@_stop |
| 392 |
{ |
| 393 |
\exp_not:N \str_if_eq:nnT |
| 394 |
{ \c_percent_str \c_percent_str BoundingBox } |
| 395 |
{#1} |
| 396 |
{ \exp_not:N \@@_read_bb_auxiv:w #2 ( ) \s_@@_stop } |
| 397 |
} |
| 398 |
} |
| 399 |
% \end{macrocode} |
| 400 |
% If the bounding box is |atend|, just ignore the current one and keep going. |
| 401 |
% Otherwise, we need to allow for tabs and multiple spaces (as the line has |
| 402 |
% been read as a string). The easiest way to deal with that is to scan the |
| 403 |
% tokens: at this stage the line fragment should be just numbers and |
| 404 |
% whitespace. \TeX{} will then tidy up for us, with just a leading space to |
| 405 |
% worry about: that is taken out by the |\use:n| here. |
| 406 |
% \begin{macrocode} |
| 407 |
\cs_new_protected:Npn \@@_read_bb_auxiv:w #1 ( #2 ) #3 \s_@@_stop |
| 408 |
{ |
| 409 |
\str_if_eq:nnF {#2} { atend } |
| 410 |
{ |
| 411 |
\tl_set_rescan:Nne \l_@@_tmp_tl |
| 412 |
{ |
| 413 |
\char_set_catcode_space:n { 9 } |
| 414 |
\char_set_catcode_space:n { 32 } |
| 415 |
} |
| 416 |
{ \use:n #1 } |
| 417 |
\exp_after:wN \@@_read_bb_auxv:w \l_@@_tmp_tl \s_@@_stop |
| 418 |
} |
| 419 |
} |
| 420 |
% \end{macrocode} |
| 421 |
% A trailing space was deliberately added earlier so we know that the final |
| 422 |
% data point is terminated by a space. |
| 423 |
% \begin{macrocode} |
| 424 |
\cs_new_protected:Npn \@@_read_bb_auxv:w #1~#2~#3~#4~#5 \s_@@_stop |
| 425 |
{ |
| 426 |
\dim_set:Nn \l_@@_llx_dim { #1 bp } |
| 427 |
\dim_set:Nn \l_@@_lly_dim { #2 bp } |
| 428 |
\dim_set:Nn \l_@@_urx_dim { #3 bp } |
| 429 |
\dim_set:Nn \l_@@_ury_dim { #4 bp } |
| 430 |
\ior_map_break: |
| 431 |
} |
| 432 |
% \end{macrocode} |
| 433 |
% \end{macro} |
| 434 |
% \end{macro} |
| 435 |
% \end{macro} |
| 436 |
% \end{macro} |
| 437 |
% \end{macro} |
| 438 |
% \end{macro} |
| 439 |
% \end{macro} |
| 440 |
% |
| 441 |
% \begin{variable}{\l_@@_final_name_str, \l_@@_full_name_str} |
| 442 |
% The full name is as you'd expect the name including path and extension. |
| 443 |
% The final name here reflects any conversions carried out by the backend, |
| 444 |
% for example if an |.eps| is converted to |.pdf|. |
| 445 |
% \begin{macrocode} |
| 446 |
\str_new:N \l_@@_final_name_str |
| 447 |
\str_new:N \l_@@_full_name_str |
| 448 |
% \end{macrocode} |
| 449 |
% \end{variable} |
| 450 |
% |
| 451 |
% \begin{variable}{\l_@@_tmp_box} |
| 452 |
% \begin{macrocode} |
| 453 |
\box_new:N \l_@@_tmp_box |
| 454 |
% \end{macrocode} |
| 455 |
% \end{variable} |
| 456 |
% |
| 457 |
% \begin{variable}{\l_@@_dir_str \l_@@_name_str \l_@@_ext_str} |
| 458 |
% \begin{macrocode} |
| 459 |
\str_new:N \l_@@_dir_str |
| 460 |
\str_new:N \l_@@_name_str |
| 461 |
\str_new:N \l_@@_ext_str |
| 462 |
% \end{macrocode} |
| 463 |
% \end{variable} |
| 464 |
% |
| 465 |
% \begin{variable}{\l_graphics_search_path_seq} |
| 466 |
% \begin{macrocode} |
| 467 |
\seq_new:N \l_graphics_search_path_seq |
| 468 |
% \end{macrocode} |
| 469 |
% \end{variable} |
| 470 |
% |
| 471 |
% \begin{variable}{\l_graphics_search_ext_seq} |
| 472 |
% Used to specify fall-back extensions: actually set on a per-backend basis. |
| 473 |
% \begin{macrocode} |
| 474 |
\seq_new:N \l_graphics_search_ext_seq |
| 475 |
% \end{macrocode} |
| 476 |
% \end{variable} |
| 477 |
% |
| 478 |
% \begin{variable}{\l_graphics_ext_type_prop} |
| 479 |
% Mapping between extensions and types for non-standard mappings |
| 480 |
% \begin{macrocode} |
| 481 |
\prop_new:N \l_graphics_ext_type_prop |
| 482 |
\prop_put:Nnn \l_graphics_ext_type_prop { .ps } { eps } |
| 483 |
% \end{macrocode} |
| 484 |
% \end{variable} |
| 485 |
% |
| 486 |
% \begin{variable}{\g_@@_record_seq} |
| 487 |
% A list of graphic files used. |
| 488 |
% \begin{macrocode} |
| 489 |
\seq_new:N \g_@@_record_seq |
| 490 |
% \end{macrocode} |
| 491 |
% \end{variable} |
| 492 |
% |
| 493 |
% \begin{macro}{\graphics_include:nn, \graphics_include:nV} |
| 494 |
% \begin{macro}{\@@_include_search:n} |
| 495 |
% \begin{macro}{\@@_include:} |
| 496 |
% \begin{macro} |
| 497 |
% { |
| 498 |
% \@@_include_auxi:n, \@@_include_auxi:e, \@@_include_auxii:n, |
| 499 |
% \@@_include_auxiii:n, \@@_include_auxiv:n |
| 500 |
% } |
| 501 |
% Actually including an graphic is relatively straight-forward: most of the |
| 502 |
% work is done by the backend. We only have to deal with making sure the |
| 503 |
% box has no apparent depth. Where the first given name is not found, we |
| 504 |
% search based on extension only if the \meta{type} was not given. The one |
| 505 |
% wrinkle is that we may have found a \texttt{.tex} file matching the file |
| 506 |
% name stem: that's not what we want, so we have to filter out. |
| 507 |
% \begin{macrocode} |
| 508 |
\cs_new_protected:Npn \graphics_include:nn #1#2 |
| 509 |
{ |
| 510 |
\group_begin: |
| 511 |
\keys_set:nn { graphics } {#1} |
| 512 |
\seq_set_eq:NN \l_file_search_path_seq \l_graphics_search_path_seq |
| 513 |
\file_get_full_name:nNTF {#2} \l_@@_full_name_str |
| 514 |
{ |
| 515 |
\str_if_eq:eeTF { \l_@@_full_name_str } { #2 .tex } |
| 516 |
{ \msg_error:nnn { graphics } { graphic-not-found } {#2} } |
| 517 |
{ \@@_include: } |
| 518 |
} |
| 519 |
{ \msg_error:nnn { graphics } { graphic-not-found } {#2} } |
| 520 |
\group_end: |
| 521 |
} |
| 522 |
\cs_generate_variant:Nn \graphics_include:nn { nV } |
| 523 |
\cs_new_protected:Npn \@@_include: |
| 524 |
{ |
| 525 |
\str_if_empty:NTF \l_@@_type_str |
| 526 |
{ |
| 527 |
\file_parse_full_name:VNNN \l_@@_full_name_str |
| 528 |
\l_@@_dir_str \l_@@_name_str \l_@@_ext_str |
| 529 |
\@@_include_auxi:e |
| 530 |
{ |
| 531 |
\exp_args:Ne \str_tail:n |
| 532 |
{ \str_casefold:V \l_@@_ext_str } |
| 533 |
} |
| 534 |
} |
| 535 |
{ \@@_include_auxi:e { \l_@@_type_str } } |
| 536 |
} |
| 537 |
\cs_new_protected:Npn \@@_include_auxi:n #1 |
| 538 |
{ |
| 539 |
\prop_get:NnNF \l_graphics_ext_type_prop { .#1 } \l_@@_tmp_tl |
| 540 |
{ \tl_set:Nn \l_@@_tmp_tl {#1} } |
| 541 |
\exp_args:NV \@@_include_auxii:n \l_@@_tmp_tl |
| 542 |
} |
| 543 |
\cs_generate_variant:Nn \@@_include_auxi:n { e } |
| 544 |
\cs_new_protected:Npn \@@_include_auxii:n #1 |
| 545 |
{ |
| 546 |
\mode_leave_vertical: |
| 547 |
\cs_if_exist:cTF { @@_backend_include_ #1 :n } |
| 548 |
{ |
| 549 |
\tl_set_eq:NN \l_@@_final_name_str \l_@@_full_name_str |
| 550 |
\str_set:Ne \l_@@_full_name_str |
| 551 |
{ \exp_args:NV \__kernel_file_name_quote:n \l_@@_full_name_str } |
| 552 |
\exp_args:NnV \use:c { @@_backend_getbb_ #1 :n } |
| 553 |
\l_@@_full_name_str |
| 554 |
\seq_gput_right:NV \g_@@_record_seq \l_@@_final_name_str |
| 555 |
\clist_if_exist:NT \@filelist |
| 556 |
{ \exp_args:NV \@addtofilelist \l_@@_final_name_str } |
| 557 |
\bool_if:NTF \l_@@_draft_bool |
| 558 |
{ \@@_include_auxiii:n } |
| 559 |
{ \@@_include_auxiv:n } |
| 560 |
{#1} |
| 561 |
} |
| 562 |
{ \msg_error:nnn { graphics } { unsupported-graphic-type } {#1} } |
| 563 |
} |
| 564 |
\cs_new_protected:Npn \@@_include_auxiii:n #1 |
| 565 |
{ |
| 566 |
\hbox_to_wd:nn { \l_@@_urx_dim - \l_@@_llx_dim } |
| 567 |
{ |
| 568 |
\tex_vrule:D |
| 569 |
\tex_hss:D |
| 570 |
\vbox_to_ht:nn |
| 571 |
{ \l_@@_ury_dim - \l_@@_lly_dim } |
| 572 |
{ |
| 573 |
\tex_hrule:D width |
| 574 |
\dim_eval:n { \l_@@_urx_dim - \l_@@_llx_dim } |
| 575 |
\tex_vss:D |
| 576 |
\hbox_to_wd:nn |
| 577 |
{ \l_@@_urx_dim - \l_@@_llx_dim } |
| 578 |
{ |
| 579 |
\ttfamily |
| 580 |
\tex_hss:D \l_@@_full_name_str \tex_hss:D |
| 581 |
} |
| 582 |
\tex_vss:D |
| 583 |
\tex_hrule:D |
| 584 |
} |
| 585 |
\tex_hss:D |
| 586 |
\tex_vrule:D |
| 587 |
} |
| 588 |
} |
| 589 |
\cs_new_protected:Npn \@@_include_auxiv:n #1 |
| 590 |
{ |
| 591 |
\hbox_set:Nn \l_@@_tmp_box |
| 592 |
{ |
| 593 |
\exp_args:NnV \use:c { @@_backend_include_ #1 :n } |
| 594 |
\l_@@_full_name_str |
| 595 |
} |
| 596 |
\box_set_dp:Nn \l_@@_tmp_box { 0pt } |
| 597 |
\box_set_ht:Nn \l_@@_tmp_box |
| 598 |
{ \l_@@_ury_dim - \l_@@_lly_dim } |
| 599 |
\box_set_wd:Nn \l_@@_tmp_box |
| 600 |
{ \l_@@_urx_dim - \l_@@_llx_dim } |
| 601 |
\box_use_drop:N \l_@@_tmp_box |
| 602 |
} |
| 603 |
% \end{macrocode} |
| 604 |
% \end{macro} |
| 605 |
% \end{macro} |
| 606 |
% \end{macro} |
| 607 |
% \end{macro} |
| 608 |
% |
| 609 |
% \begin{macro}{\graphics_show_list:, \graphics_log_list:, \@@_list:N} |
| 610 |
% \begin{macro}[EXP]{\@@_list_aux:n} |
| 611 |
% A function to list all graphic files used. |
| 612 |
% \begin{macrocode} |
| 613 |
\cs_new_protected:Npn \graphics_show_list: { \@@_list:N \msg_show:nneeee } |
| 614 |
\cs_new_protected:Npn \graphics_log_list: { \@@_list:N \msg_log:nneeee } |
| 615 |
\cs_new_protected:Npn \@@_list:N #1 |
| 616 |
{ |
| 617 |
\seq_remove_duplicates:N \g_@@_record_seq |
| 618 |
#1 { kernel } { file-list } |
| 619 |
{ \seq_map_function:NN \g_@@_record_seq \@@_list_aux:n } |
| 620 |
{ } { } { } |
| 621 |
} |
| 622 |
\cs_new:Npn \@@_list_aux:n #1 { \iow_newline: #1 } |
| 623 |
% \end{macrocode} |
| 624 |
% \end{macro} |
| 625 |
% \end{macro} |
| 626 |
% |
| 627 |
% \subsection{Utility functions} |
| 628 |
% |
| 629 |
% \begin{macro}{\graphics_get_full_name:nN} |
| 630 |
% \begin{macro}[TF]{\graphics_get_full_name:nN} |
| 631 |
% \begin{macro}{\@@_get_full_name:n} |
| 632 |
% As well as searching by path, etc., there is a need here to check that |
| 633 |
% we do not trip over |foo.bar| if |.bar| is not a known extension for |
| 634 |
% the current backend. |
| 635 |
% \begin{macrocode} |
| 636 |
\cs_new_protected:Npn \graphics_get_full_name:nN #1#2 |
| 637 |
{ |
| 638 |
\graphics_get_full_name:nNF {#1} #2 |
| 639 |
{ \tl_set:Nn #2 { \q_no_value } } |
| 640 |
} |
| 641 |
\prg_new_protected_conditional:Npnn \graphics_get_full_name:nN #1#2 |
| 642 |
{ T , F , TF } |
| 643 |
{ |
| 644 |
\group_begin: |
| 645 |
\seq_set_eq:NN \l_file_search_path_seq \l_graphics_search_path_seq |
| 646 |
\file_get_full_name:nNTF {#1} \l_@@_full_name_str |
| 647 |
{ |
| 648 |
\str_if_eq:eeTF { \l_@@_full_name_str } { #1 .tex } |
| 649 |
{ \@@_get_full_name:n {#1} } |
| 650 |
{ |
| 651 |
\file_parse_full_name:VNNN \l_@@_full_name_str |
| 652 |
\l_@@_dir_str \l_@@_name_str \l_@@_ext_str |
| 653 |
\seq_map_inline:Nn \l_graphics_search_ext_seq |
| 654 |
{ |
| 655 |
\str_if_eq:nVT {##1} \l_@@_ext_str |
| 656 |
{ \seq_map_break:n { \use_none:nn } } |
| 657 |
} |
| 658 |
\@@_get_full_name:n {#1} |
| 659 |
} |
| 660 |
} |
| 661 |
{ \@@_get_full_name:n {#1} } |
| 662 |
\exp_args:NNNV \group_end: |
| 663 |
\tl_set:Nn #2 \l_@@_full_name_str |
| 664 |
\tl_if_empty:NTF #2 |
| 665 |
{ \prg_return_false: } |
| 666 |
{ \prg_return_true: } |
| 667 |
} |
| 668 |
\cs_new_protected:Npn \@@_get_full_name:n #1 |
| 669 |
{ |
| 670 |
\str_clear:N \l_@@_full_name_str |
| 671 |
\seq_map_inline:Nn \l_graphics_search_ext_seq |
| 672 |
{ |
| 673 |
\file_get_full_name:nNT { #1 ##1 } \l_@@_full_name_str |
| 674 |
{ \seq_map_break:n { \use_none:nn } } |
| 675 |
} |
| 676 |
\use:n |
| 677 |
{ \str_clear:N \l_@@_full_name_str } |
| 678 |
} |
| 679 |
% \end{macrocode} |
| 680 |
% \end{macro} |
| 681 |
% \end{macro} |
| 682 |
% \end{macro} |
| 683 |
% |
| 684 |
% \begin{macro}{\graphics_get_pagecount:nN} |
| 685 |
% \begin{macro}{\@@_get_pagecount:n} |
| 686 |
% \begin{macro}{\@@_get_pagecount:nw} |
| 687 |
% A generic function to read the number of pages in a graphic file. This is |
| 688 |
% used by all of the backend where there is not a dedicated primitive. The |
| 689 |
% plan is essentially the same as reading the bounding box. To avoid multiple |
| 690 |
% calls, the value is cached either here or in the backend. |
| 691 |
% \begin{macrocode} |
| 692 |
\cs_new_protected:Npn \graphics_get_pagecount:nN #1#2 |
| 693 |
{ |
| 694 |
\group_begin: |
| 695 |
\seq_set_eq:NN \l_file_search_path_seq \l_graphics_search_path_seq |
| 696 |
\file_get_full_name:nNTF {#1} \l_@@_full_name_str |
| 697 |
{ |
| 698 |
\int_if_exist:cF { c_@@_ \l_@@_full_name_str _pages_int } |
| 699 |
{ |
| 700 |
\exp_args:NV \@@_backend_get_pagecount:n |
| 701 |
\l_@@_full_name_str |
| 702 |
} |
| 703 |
\tl_set:Nv #2 { c_@@_ \l_@@_full_name_str _pages_int } |
| 704 |
} |
| 705 |
{ |
| 706 |
\tl_set:Nn #2 { 0 } |
| 707 |
\msg_error:nnn { graphics } { graphic-not-found } {#1} |
| 708 |
} |
| 709 |
\exp_args:NNNV \group_end: |
| 710 |
\tl_set:Nn #2 #2 |
| 711 |
} |
| 712 |
\cs_new_protected:Npe \@@_get_pagecount:n #1 |
| 713 |
{ |
| 714 |
\exp_not:N \ior_shell_open:Nn \exp_not:N \l_@@_tmp_ior |
| 715 |
{ extractbb~-O~#1 } |
| 716 |
\exp_not:N \ior_if_eof:NTF \exp_not:N \l_@@_tmp_ior |
| 717 |
{ \msg_error:nnn { graphics } { pipe-failed } } |
| 718 |
{ |
| 719 |
\ior_str_map_inline:Nn \exp_not:N \l_@@_tmp_ior |
| 720 |
{ |
| 721 |
\exp_not:N \@@_get_pagecount:nw {#1} |
| 722 |
##1 ~ \c_colon_str \c_colon_str \s_@@_stop |
| 723 |
} |
| 724 |
\exp_not:N \int_if_exist:cF { c_@@_ #1 _pages_int } |
| 725 |
{ \int_const:cn { c_@@_ #1 _pages_int } { 1 } } |
| 726 |
} |
| 727 |
\ior_close:N \exp_not:N \l_@@_tmp_ior |
| 728 |
} |
| 729 |
\use:e |
| 730 |
{ |
| 731 |
\cs_new_protected:Npn \exp_not:N \@@_get_pagecount:nw |
| 732 |
#1#2 \c_colon_str #3 \c_colon_str #4 \s_@@_stop |
| 733 |
{ |
| 734 |
\exp_not:N \str_if_eq:nnT |
| 735 |
{ \c_percent_str \c_percent_str Pages } |
| 736 |
{#2} |
| 737 |
{ |
| 738 |
\int_const:cn { c_@@_ #1 _pages_int } {#3} |
| 739 |
\exp_not:N \ior_map_break: |
| 740 |
} |
| 741 |
} |
| 742 |
} |
| 743 |
% \end{macrocode} |
| 744 |
% \end{macro} |
| 745 |
% \end{macro} |
| 746 |
% \end{macro} |
| 747 |
% |
| 748 |
% \subsection{Messages} |
| 749 |
% |
| 750 |
% \begin{macrocode} |
| 751 |
\msg_new:nnnn { graphics } { graphic-not-found } |
| 752 |
{ Image~file~'#1'~not~found. } |
| 753 |
{ |
| 754 |
LaTeX~tried~to~open~graphic~file~'#1',~ |
| 755 |
but~the~file~could~not~be~read. |
| 756 |
} |
| 757 |
\msg_new:nnnn { graphics } { pipe-failed } |
| 758 |
{ Cannot~run~piped~system~commands. } |
| 759 |
{ |
| 760 |
LaTeX~tried~to~call~a~system~process~but~this~was~not~possible.\\ |
| 761 |
Try~the~"--shell-escape"~(or~"--enable-pipes")~option. |
| 762 |
} |
| 763 |
\msg_new:nnnn { graphics } { unsupported-graphic-type } |
| 764 |
{ Image~type~'#1'~not~supported~by~current~driver. } |
| 765 |
{ |
| 766 |
LaTeX~was~asked~to~include~an~graphic~of~type~'#1',~ |
| 767 |
but~this~is~not~supported~by~the~current~driver~(production~route). |
| 768 |
} |
| 769 |
% \end{macrocode} |
| 770 |
% |
| 771 |
% \begin{macrocode} |
| 772 |
%</code> |
| 773 |
% \end{macrocode} |
| 774 |
% |
| 775 |
% \end{implementation} |
| 776 |
% |
| 777 |
% \PrintIndex |