I have used SWP a lot in the past, and really like that product (despite some 
limitations). They support “fragments” which is really great:

·        Mark any part of a document, and save this marked part as a “fragment” 
in a file of a given name.

·        Then call back this fragment by typing Ctrl+ fragment name at any time 
(v 5.5). (Use of the Ctrl key makes it slightly complex to type, so there may 
be better ways).

·        Examples of fragments could be (I) horizontal fill + math 
\blacktriangle (e.g named endex – end of example) (ii) a floating table with 
center table (e.g, mytab), (iii) similar for figures (e.g, myfig), (iv) a 
symbol for scaled variables (e.g, scaled), (v) an empty data list object set to 
the Python language, numbered lines on the left side with smallest font using 
typewriter font (e.g, mypython), etc., etc.
In summary: fragments are great – very useful, and very intuitive to use! 
Sorely missed.

-Bernt

From: Richard Heck<mailto:rgh...@lyx.org>
Sent: Thursday, August 11, 2016 21:08
To: Bernt Lie<mailto:bernt....@hit.no>; 
lyx-users@lists.lyx.org<mailto:lyx-users@lists.lyx.org>
Subject: Re: How to define "fragments" within LyX 2.2.1?

On 08/11/2016 07:43 AM, Bernt Lie wrote:
Preliminaries: I use Windows 10 with LyX 2.2.1.

I need to have some symbol to close Examples. Here is what I do:

·         I change the first paragraph in an example from Standard to Example. 
This allows me to number the example, and I can insert a marker/label so that I 
can refer to the example.

·         I choose to let the subsequent paragraphs within the example be 
standard paragraphs, so that I am not limited by the layout constraints within 
theorem-like elements.

What is the problem here?


·         I then need some symbol to indicate the end of an example (I would 
need that anyway, because LyX seems to typeset example “body text” in roman 
font, contrary to the default of “old LaTeX” – personally, I welcome this, 
because example text is often lengthy, and it looks bad with a lengthy text in 
italic...)

·         OK – the symbol I have chosen to close the example is: “Horizontal 
fill” + math symbol “\blacktriangle”. This will push a black (upward pointing) 
triangle to the right margin. The triangle is supposed to point into the 
example...

·         Is there a way that I can give a *name* to this combination of 
“Horizontal fill” + “black triangle”, so that I can easily insert it? I’d like 
to call it “endex” (end-of-example), or something like that. How can I insert 
this “user defined” combination (“fragment”) into the LyX document with a 
simple keyboard short-cut?

Two answers.

To do this the way you describe, simply do it the way you could do it in LaTeX:
    \newcommand\endex{\hfill$\blacktriangle$}
Then put "\endex" in TeX code where you need it.

A better way to do it would be to define your own environment, one that ended 
this way. To do so, I'd suggest mimicking or modifying the proof environment. 
There's an issue about how the closing symbol is handled when the line is long, 
one you'll likely see if you do this the first way. The proof environment 
contains code to handle that, which you can simply adapt.

Obviously, that means getting yourself into the LaTeX code, but that's 
inevitable if you want to do this kind of customization.

Richard

PS It's possible there are LaTeX packages that would help with this. You might 
try asking at stack exchange.

Reply via email to