How to assign a key code to a local layout
Tobias Hilbricht
hilbricht at linopus.de
Mon Aug 9 14:18:41 UTC 2021
Am Sonntag, den 08.08.2021, 16:21 -0400 schrieb Steve Litt:
> Tobias Hilbricht said on Sun, 08 Aug 2021 19:48:21 +0200
>
> > Am Sonntag, den 04.07.2021, 11:53 -0400 schrieb Richard Kimberly
> > Heck:
> > > On 7/4/21 9:50 AM, Tobias Hilbricht wrote:
> > > > Dear readers of this list,
> > > >
> > > > I created a local layout (Document -> Settings -> Local layout)
> > > > which I
> > > > can invoke via the menu (Insert -> User defined insert -> Local
> > > > insert)
> > > > and which works as expected.
> > > > How can I assign a key code to this local layout?
> > >
> > > Probably "flex-insert INSETNAME" is what you want. Just assign
> > > that
> > > command to a key combination.
> > >
> > > Riki
> > >
> > >
> > >
> > Just in case somebody comes across this thread in quest of an
> > answer to
> > the question how to make the assigned key code appear together with
> > the
> > entry in the menu - here something I found out accidentally and
> > which
> > I did not find documented:
> >
> > If I type
> >
> > flex-insert "mycustominsert"
> >
> > - note the quotation marks - and assign a key code, then the key
> > code
> > appears in the menu Insert -> Custom insert -> mycustominsert.
>
> If I understand the preceding several posts correctly, this can give
> me
> a capability I've been wanting for years. If anybody has the code to
> make a custom insert in a local layout file, could you please post it
> so
> I can replicate your work? To me, it's not at all obvious how to do
> this.
>
> Thanks,
>
> SteveT
>
> Steve Litt
> Spring 2021 featured book: Troubleshooting Techniques of the
> Successful
> Technologist http://www.troubleshooters.com/techniques
How to LyXify frequently used LaTeX custom commands
First Example: If you have defined a LaTeX custom command - either in
the LaTeX class file, in a LaTeX style file, in the LyX document
preamble or as ERT in the LyX document itself, e. g.
\newcommand\bigsize[1]{{\fontsize{50}{60}\selectfont #1 }}
then you can write all of the following in LyX Document -> Settings ->
Local format:
Format 66
InsetLayout Flex:KingSize!
LyXType custom
Decoration classic
LatexType command
LatexName bigsize
LabelString "Big!"
End
Press the button "Validate", it should return something like "Format is
valid", then press "OK". Now you will find the menu entry "KingSize!"
in LyX Insert -> Custom Insert, and when you click it you can enter
text.
To assign a key code to the new custom inset, go to LyX Tools ->
Settings -> Edit -> Key Board Short Cut -> New and enter the following
line into the text field:
flex-insert "KingSize!"
Click into the gray field "Key board shortcut" and press the keys you
want to assign.
Second Example: I frequently need Rechenkästchen - I do not know the
English word - to this end I have in LaTeX
\usepackage{tikz}
\newcommand\kariert[2][0.5cm]{%
\begin{tikzpicture}[gray,step=#1]
\pgfmathtruncatemacro\anzahl{(\linewidth-\pgflinewidth)/#1} %
maximale Anzahl Kästchen pro Zeile
\draw (0,0) rectangle (\anzahl*#1,#2*#1) (0,0) grid
(\anzahl*#1,#2*#1);
\end{tikzpicture}
}
This provides the command
\kariert[size]{rownumber}
with the mandatory argument rownumber and the optional argument size,
e. g.
\kariert[8mm]{6}
results in 6 rows of 8mm sized Rechenkästchen. To test invocation in
LyX conveniently, write the following in LyX Document -> Settings ->
Local Format:
Format 66
InsetLayout Flex:Kästchen
LyxType custom
Decoration Classic
LabelString "Kästchen"
LatexName kariert
LatexType command
Argument 1
LabelString "Größe"
Mandatory 0
EndArgument
End
Validate and press OK, go to LyX Insert -> Custom Insert -> Kästchen
and press again. Enter a number of rows, compile and see. To modify the
size, right click on the number just entered und press "Größe" in the
context menu (or the corresponding key code), now you can type a size
in dimensions known to LaTeX.
If local formats have been tested as described in the two examples,
they can be written in a layout-file as described in the LyX Customize-
manual, chapter 5. All this is for text-mode commands. I did not get it
to work with LyX math macros.
Yours
Tobias
More information about the lyx-users
mailing list