I have a document with several images from a few different sources. I'd like to indicate different formatting options for each source. I understand I can use graphics groups for this, but I don't know how I can enter complex formatting command for this.

To give an example of a complex command, for a given group, I'd like to have the image width equals the smaller of 75% of the size of the original image, or the line width.

From another question, I got this handy macro, which works well across the whole document:

\setkeys{Gin}{width=\ifdim 0.75\Gin@nat@width>\linewidth

However, trying to paste that code into the LaTeX Options text box in the graphics settings dialog does not work.

Any pointers?

  • By "groups" are you referring to (say) a section within your document? Different sections refer to different groups? – Werner May 15 '15 at 0:27
  • @Werner No, groups are ways to tag graphics objects so that they share formatting settings. If you change the settings in a graphic that's in a group, Lyx makes that change in all the other graphics in the same group, regardless of where they are in the document. – João Mendes May 15 '15 at 8:55

Best here would be to define group-specific key-value options. This would allow you to set a single option associated with the group, while LaTeX manages the back-end setting for the option.

As an example of this, add the following to your Document > Settings... > LaTeX Preamble:

  \setkeys{Gin}{width=\ifdim 0.75\Gin@nat@width>\linewidth

The above* defines a "boolean key" groupAoptions which you can now call using

enter image description here

Of course, now you can include many group-specific options into the single groupAoptions key, if you wish.

* Note there is no requirement for using a \makeatletter...\makeatother pair in the LaTeX Preamble for LyX, as this is inserted automatically.

  • Stellar. Worked like a charm. :) Thank you also for the \makeatletter tip – João Mendes May 18 '15 at 9:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.