How to define a comma separated list of arguments for includegraphics

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite
1












I have a large set of pictures, and I want to apply predefined settings to each using the optional argument of the includegraphics macro from the graphicx package.



I would like to define the settings once at the top of the file (like defsettingswidth=textwidth, angle=90), and then apply them to all of my images so that I can modify all of the settings from one place.



If I run the following code block, it gives me the versions of the error "Package xkeyval Error: 'width=textwidth, angle=90' undefined in families 'Gin'", which seems to be because it's interpreting my entire group of settings as a single key input.



documentclassarticle
usepackagegraphix
begindocument

defsettingsAwidth=textwidth, angle=90
defsettingsBpage=1, scale=.1
defsettingsCangle=90, scale=.5

beginfigure
includegraphics[settingsA]filename1.png
labelfig:oneofonehundred
endfigure

beginfigure
includegraphics[settingsB]filename2.pdf
labelfig:twoofonehundred
endfigure

beginfigure
includegraphics[settingsC]filename3.jpg
labelfig:threeofonehundred
endfigure

enddocument


What is the technique to modify this settings string so that it is interpreted correctly? How do I pass an optional argument that is interpreted as a set of arguments instead of one string?



Thanks in advance!










share|improve this question

















  • 2




    expandafterincludegrapgicsexpandafter[settingsA]... untested (currently not at pc), the key value interpreter does not expand the optional argument before parsing it
    – daleif
    Sep 28 at 6:27










  • In my opinion, built-in expansion of the optional arg of includegraphics is worth being filed as a feature request to github.com/latex3/latex2e/issues?utf8=%E2%9C%93&q=graphicx
    – AlexG
    Sep 28 at 8:23














up vote
7
down vote

favorite
1












I have a large set of pictures, and I want to apply predefined settings to each using the optional argument of the includegraphics macro from the graphicx package.



I would like to define the settings once at the top of the file (like defsettingswidth=textwidth, angle=90), and then apply them to all of my images so that I can modify all of the settings from one place.



If I run the following code block, it gives me the versions of the error "Package xkeyval Error: 'width=textwidth, angle=90' undefined in families 'Gin'", which seems to be because it's interpreting my entire group of settings as a single key input.



documentclassarticle
usepackagegraphix
begindocument

defsettingsAwidth=textwidth, angle=90
defsettingsBpage=1, scale=.1
defsettingsCangle=90, scale=.5

beginfigure
includegraphics[settingsA]filename1.png
labelfig:oneofonehundred
endfigure

beginfigure
includegraphics[settingsB]filename2.pdf
labelfig:twoofonehundred
endfigure

beginfigure
includegraphics[settingsC]filename3.jpg
labelfig:threeofonehundred
endfigure

enddocument


What is the technique to modify this settings string so that it is interpreted correctly? How do I pass an optional argument that is interpreted as a set of arguments instead of one string?



Thanks in advance!










share|improve this question

















  • 2




    expandafterincludegrapgicsexpandafter[settingsA]... untested (currently not at pc), the key value interpreter does not expand the optional argument before parsing it
    – daleif
    Sep 28 at 6:27










  • In my opinion, built-in expansion of the optional arg of includegraphics is worth being filed as a feature request to github.com/latex3/latex2e/issues?utf8=%E2%9C%93&q=graphicx
    – AlexG
    Sep 28 at 8:23












up vote
7
down vote

favorite
1









up vote
7
down vote

favorite
1






1





I have a large set of pictures, and I want to apply predefined settings to each using the optional argument of the includegraphics macro from the graphicx package.



I would like to define the settings once at the top of the file (like defsettingswidth=textwidth, angle=90), and then apply them to all of my images so that I can modify all of the settings from one place.



If I run the following code block, it gives me the versions of the error "Package xkeyval Error: 'width=textwidth, angle=90' undefined in families 'Gin'", which seems to be because it's interpreting my entire group of settings as a single key input.



documentclassarticle
usepackagegraphix
begindocument

defsettingsAwidth=textwidth, angle=90
defsettingsBpage=1, scale=.1
defsettingsCangle=90, scale=.5

beginfigure
includegraphics[settingsA]filename1.png
labelfig:oneofonehundred
endfigure

beginfigure
includegraphics[settingsB]filename2.pdf
labelfig:twoofonehundred
endfigure

beginfigure
includegraphics[settingsC]filename3.jpg
labelfig:threeofonehundred
endfigure

enddocument


What is the technique to modify this settings string so that it is interpreted correctly? How do I pass an optional argument that is interpreted as a set of arguments instead of one string?



Thanks in advance!










share|improve this question













I have a large set of pictures, and I want to apply predefined settings to each using the optional argument of the includegraphics macro from the graphicx package.



I would like to define the settings once at the top of the file (like defsettingswidth=textwidth, angle=90), and then apply them to all of my images so that I can modify all of the settings from one place.



If I run the following code block, it gives me the versions of the error "Package xkeyval Error: 'width=textwidth, angle=90' undefined in families 'Gin'", which seems to be because it's interpreting my entire group of settings as a single key input.



documentclassarticle
usepackagegraphix
begindocument

defsettingsAwidth=textwidth, angle=90
defsettingsBpage=1, scale=.1
defsettingsCangle=90, scale=.5

beginfigure
includegraphics[settingsA]filename1.png
labelfig:oneofonehundred
endfigure

beginfigure
includegraphics[settingsB]filename2.pdf
labelfig:twoofonehundred
endfigure

beginfigure
includegraphics[settingsC]filename3.jpg
labelfig:threeofonehundred
endfigure

enddocument


What is the technique to modify this settings string so that it is interpreted correctly? How do I pass an optional argument that is interpreted as a set of arguments instead of one string?



Thanks in advance!







errors optional-arguments strings arguments






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 28 at 6:16









J. Zar

362




362







  • 2




    expandafterincludegrapgicsexpandafter[settingsA]... untested (currently not at pc), the key value interpreter does not expand the optional argument before parsing it
    – daleif
    Sep 28 at 6:27










  • In my opinion, built-in expansion of the optional arg of includegraphics is worth being filed as a feature request to github.com/latex3/latex2e/issues?utf8=%E2%9C%93&q=graphicx
    – AlexG
    Sep 28 at 8:23












  • 2




    expandafterincludegrapgicsexpandafter[settingsA]... untested (currently not at pc), the key value interpreter does not expand the optional argument before parsing it
    – daleif
    Sep 28 at 6:27










  • In my opinion, built-in expansion of the optional arg of includegraphics is worth being filed as a feature request to github.com/latex3/latex2e/issues?utf8=%E2%9C%93&q=graphicx
    – AlexG
    Sep 28 at 8:23







2




2




expandafterincludegrapgicsexpandafter[settingsA]... untested (currently not at pc), the key value interpreter does not expand the optional argument before parsing it
– daleif
Sep 28 at 6:27




expandafterincludegrapgicsexpandafter[settingsA]... untested (currently not at pc), the key value interpreter does not expand the optional argument before parsing it
– daleif
Sep 28 at 6:27












In my opinion, built-in expansion of the optional arg of includegraphics is worth being filed as a feature request to github.com/latex3/latex2e/issues?utf8=%E2%9C%93&q=graphicx
– AlexG
Sep 28 at 8:23




In my opinion, built-in expansion of the optional arg of includegraphics is worth being filed as a feature request to github.com/latex3/latex2e/issues?utf8=%E2%9C%93&q=graphicx
– AlexG
Sep 28 at 8:23










2 Answers
2






active

oldest

votes

















up vote
10
down vote













Just define new keys:



documentclassarticle
usepackagegraphicx

makeatletter
define@keyGinsettingsAsetkeysGinwidth=textwidth, angle=90
define@keyGinsettingsBsetkeysGinpage=1, scale=.1
define@keyGinsettingsCsetkeysGinangle=-90, scale=.5
makeatother

begindocument

includegraphics[settingsA]example-image-a

includegraphics[settingsB]example-image-b

includegraphics[settingsC]example-image-c

enddocument


enter image description here



A bit of explanation. The graphicx package relies on keyval provided key-value syntax and reserves Gin (Graphic inclusion) as the family name of the keys for includegraphics. A new key is simply added by



define@keyGin<name>[<default value>]<code>


The includegraphics[<options>]file command will do



setkeysGin<options>


and every known key will be processed. The default empty value given for settingsA and so on is so that you can simply type settingsA without =something.



One could even improve it; say that in settingsC you want to be able to vary the angle; with



define@keyGinsettingsC[-90]setkeysGinangle=#1, scale=.5


you can specify settingsC for the angle to be -90 or



settingsC=45


for the angle to be 45.



Caveat Be sure not to define an already existing key: define@key would silently overwrite it.






share|improve this answer





























    up vote
    2
    down vote













    Make your own include graphics command. Something like the following:



    newcommandmyincludegraphics[2]%%
    expandafterincludegraphicsexpandafter[#1]#2


    The problem with your code is that in the construction



    includegraphics[settingsA]filehandle


    The unexpanded settingsA is getting passed to the key parser where it will fail to match any keys. By using the above command, you can write something like,



    myincludegraphicssettingsAfilehandle


    By using expandafter, settingsA will be expanded by the time includegraphics has a chance to pass the optional arguments to its parser.






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "85"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f452882%2fhow-to-define-a-comma-separated-list-of-arguments-for-includegraphics%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      10
      down vote













      Just define new keys:



      documentclassarticle
      usepackagegraphicx

      makeatletter
      define@keyGinsettingsAsetkeysGinwidth=textwidth, angle=90
      define@keyGinsettingsBsetkeysGinpage=1, scale=.1
      define@keyGinsettingsCsetkeysGinangle=-90, scale=.5
      makeatother

      begindocument

      includegraphics[settingsA]example-image-a

      includegraphics[settingsB]example-image-b

      includegraphics[settingsC]example-image-c

      enddocument


      enter image description here



      A bit of explanation. The graphicx package relies on keyval provided key-value syntax and reserves Gin (Graphic inclusion) as the family name of the keys for includegraphics. A new key is simply added by



      define@keyGin<name>[<default value>]<code>


      The includegraphics[<options>]file command will do



      setkeysGin<options>


      and every known key will be processed. The default empty value given for settingsA and so on is so that you can simply type settingsA without =something.



      One could even improve it; say that in settingsC you want to be able to vary the angle; with



      define@keyGinsettingsC[-90]setkeysGinangle=#1, scale=.5


      you can specify settingsC for the angle to be -90 or



      settingsC=45


      for the angle to be 45.



      Caveat Be sure not to define an already existing key: define@key would silently overwrite it.






      share|improve this answer


























        up vote
        10
        down vote













        Just define new keys:



        documentclassarticle
        usepackagegraphicx

        makeatletter
        define@keyGinsettingsAsetkeysGinwidth=textwidth, angle=90
        define@keyGinsettingsBsetkeysGinpage=1, scale=.1
        define@keyGinsettingsCsetkeysGinangle=-90, scale=.5
        makeatother

        begindocument

        includegraphics[settingsA]example-image-a

        includegraphics[settingsB]example-image-b

        includegraphics[settingsC]example-image-c

        enddocument


        enter image description here



        A bit of explanation. The graphicx package relies on keyval provided key-value syntax and reserves Gin (Graphic inclusion) as the family name of the keys for includegraphics. A new key is simply added by



        define@keyGin<name>[<default value>]<code>


        The includegraphics[<options>]file command will do



        setkeysGin<options>


        and every known key will be processed. The default empty value given for settingsA and so on is so that you can simply type settingsA without =something.



        One could even improve it; say that in settingsC you want to be able to vary the angle; with



        define@keyGinsettingsC[-90]setkeysGinangle=#1, scale=.5


        you can specify settingsC for the angle to be -90 or



        settingsC=45


        for the angle to be 45.



        Caveat Be sure not to define an already existing key: define@key would silently overwrite it.






        share|improve this answer
























          up vote
          10
          down vote










          up vote
          10
          down vote









          Just define new keys:



          documentclassarticle
          usepackagegraphicx

          makeatletter
          define@keyGinsettingsAsetkeysGinwidth=textwidth, angle=90
          define@keyGinsettingsBsetkeysGinpage=1, scale=.1
          define@keyGinsettingsCsetkeysGinangle=-90, scale=.5
          makeatother

          begindocument

          includegraphics[settingsA]example-image-a

          includegraphics[settingsB]example-image-b

          includegraphics[settingsC]example-image-c

          enddocument


          enter image description here



          A bit of explanation. The graphicx package relies on keyval provided key-value syntax and reserves Gin (Graphic inclusion) as the family name of the keys for includegraphics. A new key is simply added by



          define@keyGin<name>[<default value>]<code>


          The includegraphics[<options>]file command will do



          setkeysGin<options>


          and every known key will be processed. The default empty value given for settingsA and so on is so that you can simply type settingsA without =something.



          One could even improve it; say that in settingsC you want to be able to vary the angle; with



          define@keyGinsettingsC[-90]setkeysGinangle=#1, scale=.5


          you can specify settingsC for the angle to be -90 or



          settingsC=45


          for the angle to be 45.



          Caveat Be sure not to define an already existing key: define@key would silently overwrite it.






          share|improve this answer














          Just define new keys:



          documentclassarticle
          usepackagegraphicx

          makeatletter
          define@keyGinsettingsAsetkeysGinwidth=textwidth, angle=90
          define@keyGinsettingsBsetkeysGinpage=1, scale=.1
          define@keyGinsettingsCsetkeysGinangle=-90, scale=.5
          makeatother

          begindocument

          includegraphics[settingsA]example-image-a

          includegraphics[settingsB]example-image-b

          includegraphics[settingsC]example-image-c

          enddocument


          enter image description here



          A bit of explanation. The graphicx package relies on keyval provided key-value syntax and reserves Gin (Graphic inclusion) as the family name of the keys for includegraphics. A new key is simply added by



          define@keyGin<name>[<default value>]<code>


          The includegraphics[<options>]file command will do



          setkeysGin<options>


          and every known key will be processed. The default empty value given for settingsA and so on is so that you can simply type settingsA without =something.



          One could even improve it; say that in settingsC you want to be able to vary the angle; with



          define@keyGinsettingsC[-90]setkeysGinangle=#1, scale=.5


          you can specify settingsC for the angle to be -90 or



          settingsC=45


          for the angle to be 45.



          Caveat Be sure not to define an already existing key: define@key would silently overwrite it.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 28 at 8:55

























          answered Sep 28 at 8:36









          egreg

          687k8418313078




          687k8418313078




















              up vote
              2
              down vote













              Make your own include graphics command. Something like the following:



              newcommandmyincludegraphics[2]%%
              expandafterincludegraphicsexpandafter[#1]#2


              The problem with your code is that in the construction



              includegraphics[settingsA]filehandle


              The unexpanded settingsA is getting passed to the key parser where it will fail to match any keys. By using the above command, you can write something like,



              myincludegraphicssettingsAfilehandle


              By using expandafter, settingsA will be expanded by the time includegraphics has a chance to pass the optional arguments to its parser.






              share|improve this answer
























                up vote
                2
                down vote













                Make your own include graphics command. Something like the following:



                newcommandmyincludegraphics[2]%%
                expandafterincludegraphicsexpandafter[#1]#2


                The problem with your code is that in the construction



                includegraphics[settingsA]filehandle


                The unexpanded settingsA is getting passed to the key parser where it will fail to match any keys. By using the above command, you can write something like,



                myincludegraphicssettingsAfilehandle


                By using expandafter, settingsA will be expanded by the time includegraphics has a chance to pass the optional arguments to its parser.






                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Make your own include graphics command. Something like the following:



                  newcommandmyincludegraphics[2]%%
                  expandafterincludegraphicsexpandafter[#1]#2


                  The problem with your code is that in the construction



                  includegraphics[settingsA]filehandle


                  The unexpanded settingsA is getting passed to the key parser where it will fail to match any keys. By using the above command, you can write something like,



                  myincludegraphicssettingsAfilehandle


                  By using expandafter, settingsA will be expanded by the time includegraphics has a chance to pass the optional arguments to its parser.






                  share|improve this answer












                  Make your own include graphics command. Something like the following:



                  newcommandmyincludegraphics[2]%%
                  expandafterincludegraphicsexpandafter[#1]#2


                  The problem with your code is that in the construction



                  includegraphics[settingsA]filehandle


                  The unexpanded settingsA is getting passed to the key parser where it will fail to match any keys. By using the above command, you can write something like,



                  myincludegraphicssettingsAfilehandle


                  By using expandafter, settingsA will be expanded by the time includegraphics has a chance to pass the optional arguments to its parser.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 28 at 6:28









                  A.Ellett

                  35.2k1063163




                  35.2k1063163



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f452882%2fhow-to-define-a-comma-separated-list-of-arguments-for-includegraphics%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?