TransWikia.com

includegraphics without file extension

TeX - LaTeX Asked by nir on August 6, 2020

How can I use includegraphics when I want to include an image which has no extension?

When I try to set type=jpg by hand I get the following error:
LaTeX Error: Cannot determine size of graphic in images/posters/sample (no size specified)

If I change the sample to sample.jpg all works, but I have a bunch of theses images for which I cannot change the suffix (another application depends on it).

Any advice?

One Answer

I can't think of a simple solution, but here's a possible solution that adapts the internals command used by includegraphics.

documentclass{article}
usepackage{graphicx} 

makeatletter
newcommand{jpg@Ginclude@graphics}[1]{%
  begingroup
   letinput@pathGinput@path
   filename@parse{#1}%
   defGin@ext{.jpg}%
   defGin@base{filename@areafilename@base}%
   Gread@jpg{Gin@base}%
   Gin@viewport@codeGin@nat@heightGin@ury bp%
   advanceGin@nat@height-Gin@lly bp%
   Gin@nat@width Gin@urx bp%
   advanceGin@nat@width-Gin@llx bp%
   Gin@req@sizes
   expandafterifxcsname Ginclude@jpgendcsnamerelax
     Gin@drafttrue
     expandafterifxcsname Gread@jpgendcsnamerelax
       @latex@error {Can not include graphics of type: jpg}@ehc
       globalletGread@jpg@empty
     fi
   fi
   leavevmode
   ifGin@draft
     hb@xt@
     Gin@req@width{vrule hss vbox to Gin@req@height{hrule @width
      Gin@req@width vss
      edef@tempa{Gin@base}%
      rlap{ttfamilyexpandafterstrip@prefixmeaning@tempa}%
       vsshrule}hssvrule
     }%
   else
    @addtofilelist{Gin@base}%
    ProvidesFile{Gin@base}[Graphic file (type jpg)]%
    setboxz@hbox{Ginclude@jpg{Gin@base}}%
    dpz@z@htz@Gin@req@heightwdz@Gin@req@widthboxz@
   fi
  endgroup
}%

newcommand{includejpgnoext}[2][]{%
 begingroup
  letGinclude@graphicsjpg@Ginclude@graphics
  includegraphics[#1]{#2}%
 endgroup
}

makeatother

begin{document}
includejpgnoext{sample} % jpg image file called 'sample' with no extension   
end{document}

It only works with PDFLaTeX.

Answered by Nicola Talbot on August 6, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP