3

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:

\makeatletter
\setkeys{Gin}{width=\ifdim 0.75\Gin@nat@width>\linewidth
  \linewidth
\else
  0.75\Gin@nat@width
\fi}
\makeatother

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 00: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 08:55

1 Answers1

2

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:

\usepackage{xkeyval}
\define@boolkey{Gin}{groupAoptions}[true]{%
  \setkeys{Gin}{width=\ifdim 0.75\Gin@nat@width>\linewidth
    \linewidth
  \else
    0.75\Gin@nat@width
  \fi}}

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.

Werner
  • 603,163