Discussion:
Missing features in Flex insets and style definition question
(too old to reply)
Uwe Stöhr
2011-07-18 17:46:54 UTC
Permalink
I often have the case that I need to define an inset that is internally a LaTeX command. I use for
this the Flex inset. But why does it not support optional and required arguments. I mean it
represents a LaTeX command, the same way as a normal Style declaration.
Using
OptionalArgs 1
RequiredArgs 1
in a style works very well, but I need the same also for InsetLayout Flex:.

Can this be implemented or is this already available in another form?

Besides this, is there a way to define a normal style that LyX does not treat as a paragraph. I mean
when I use

LatexType command

LyX nevertheless ends the style in the TeX output with a new line, e.g.

\test{bla}

This is an example

instead of

\test{bla}This is an example

How can I get the latter?

thanks and regards
Uwe
Richard Heck
2011-07-18 20:26:00 UTC
Permalink
Post by Uwe Stöhr
I often have the case that I need to define an inset that is
internally a LaTeX command. I use for this the Flex inset. But why
does it not support optional and required arguments. I mean it
represents a LaTeX command, the same way as a normal Style declaration.
Using
OptionalArgs 1
RequiredArgs 1
in a style works very well, but I need the same also for InsetLayout Flex:.
Can this be implemented or is this already available in another form?
I suppose it could be implemented. Of course, you can probably use ERT,
but....
Post by Uwe Stöhr
Besides this, is there a way to define a normal style that LyX does
not treat as a paragraph. I mean when I use
LatexType command
LyX nevertheless ends the style in the TeX output with a new line, e.g.
\test{bla}
This is an example
instead of
\test{bla}This is an example
How can I get the latter?
Styles in this sense are paragraph-level entities, so I don't think you
can do this. Flex insets are what you would want in this case.

Richard
Jean-Marc Lasgouttes
2011-07-18 20:30:00 UTC
Permalink
Post by Richard Heck
Styles in this sense are paragraph-level entities, so I don't think you
can do this. Flex insets are what you would want in this case.
It would be possible using parbreakisnewline if this was made to work
generally.

JMarc
Uwe Stöhr
2011-07-19 01:21:03 UTC
Permalink
Post by Richard Heck
Styles in this sense are paragraph-level entities, so I don't think you
can do this. Flex insets are what you would want in this case.
It would be possible using parbreakisnewline if this was made to work generally.
This doesn't help, because in some cases you need the feature that LyX does not add nothing, no par
break and also no newline but to continue with the code right after the command. Richard is right
that InsetLayout is designed for this, but this is only usable if InsetLayout supports also
arguments. It is not yet clear to me why this is not supported. I'm not familiar with the layout
code but I assumed that it should not be very hard to implement. Would at least be a very valuable
feature for LyX 2.1.

regards Uwe
Jean-Marc Lasgouttes
2011-07-19 08:15:51 UTC
Permalink
Post by Uwe Stöhr
This doesn't help, because in some cases you need the feature that LyX
does not add nothing, no par break and also no newline but to continue
with the code right after the command.
Looks like a very badly coded macro, then. It might be easier to fix the
problem there.
Post by Uwe Stöhr
Richard is right that InsetLayout
is designed for this, but this is only usable if InsetLayout supports
also arguments. It is not yet clear to me why this is not supported. I'm
not familiar with the layout code but I assumed that it should not be
very hard to implement. Would at least be a very valuable feature for
LyX 2.1.
Yes, it should be done eventually, and it is not very difficult.
However, I think it would be better to factor in the two cases, rather
then duplicating code (with subtly different bugs :)

JMarc
Uwe Stöhr
2011-07-19 11:47:23 UTC
Permalink
Post by Jean-Marc Lasgouttes
Post by Uwe Stöhr
This doesn't help, because in some cases you need the feature that LyX
does not add nothing, no par break and also no newline but to continue
with the code right after the command.
Looks like a very badly coded macro, then.
No, these cases occur often. They are also not "badly coded" but standard and valid LaTeX that
commands affect the paragraph they are in.

As said, we already support such LaTeX commands via InsetLayout, but we need to add for InsetLayout
also the support of arguments.
Post by Jean-Marc Lasgouttes
Post by Uwe Stöhr
Richard is right that InsetLayout
is designed for this, but this is only usable if InsetLayout supports
also arguments. It is not yet clear to me why this is not supported. I'm
not familiar with the layout code but I assumed that it should not be
very hard to implement. Would at least be a very valuable feature for
LyX 2.1.
Yes, it should be done eventually, and it is not very difficult. However, I think it would be better
to factor in the two cases, rather then duplicating code (with subtly different bugs :)
Will you do this or is this something for Richard? Should I open an enhancement bug report?

regards Uwe
Jean-Marc Lasgouttes
2011-07-19 12:23:50 UTC
Permalink
Post by Uwe Stöhr
No, these cases occur often. They are also not "badly coded" but
standard and valid LaTeX that commands affect the paragraph they are in.
What typical examples do you have in mind?

JMarc
Uwe Stöhr
2011-07-19 12:28:17 UTC
Permalink
Post by Jean-Marc Lasgouttes
Post by Uwe Stöhr
No, these cases occur often. They are also not "badly coded" but
standard and valid LaTeX that commands affect the paragraph they are in.
What typical examples do you have in mind?
Pictures in paragraphs (e.g. via picins, picinpar), wrapped floats, initials, email commands,
address formatting commands, various scientific paper titling commands, ...

regards Uwe
Jean-Marc Lasgouttes
2011-07-19 12:38:00 UTC
Permalink
Post by Uwe Stöhr
Pictures in paragraphs (e.g. via picins, picinpar), wrapped floats,
initials, email commands, address formatting commands, various
scientific paper titling commands, ...
Most of these are indeed part of a paragraph an thus should be handled
by custom insets. There is no point to change normal layouts for them.

JMarc
Uwe Stöhr
2011-07-19 12:41:57 UTC
Permalink
Most of these are indeed part of a paragraph an thus should be handled by custom insets. There is no
point to change normal layouts for them.
Yes, we already agree here. The only pint is that InsetLayout (a.k.a. flex inset) does not yet
support arguments, but we need this for many cases. For example many paper titling commands support
optional arguments (for second authors, reviewers, editors), and some of our templates/example files
look currently a bit ugly in LyX with some TeX code because of the missing argument support.

regards Uwe
Jean-Marc Lasgouttes
2011-07-19 12:25:25 UTC
Permalink
Post by Uwe Stöhr
Post by Jean-Marc Lasgouttes
Yes, it should be done eventually, and it is not very difficult.
However, I think it would be better
to factor in the two cases, rather then duplicating code (with subtly different bugs :)
Will you do this or is this something for Richard? Should I open an enhancement bug report?
I do not think I will have time to do it, unfortunately.

JMarc
Richard Heck
2011-07-19 13:08:32 UTC
Permalink
Post by Jean-Marc Lasgouttes
Post by Uwe Stöhr
Post by Jean-Marc Lasgouttes
Yes, it should be done eventually, and it is not very difficult.
However, I think it would be better
to factor in the two cases, rather then duplicating code (with subtly different bugs :)
Will you do this or is this something for Richard? Should I open an
enhancement bug report?
I do not think I will have time to do it, unfortunately.
I'm still hoping to do some major reworking of how arguments are
handled, i.e., get rid of that inset. It should be easy to include this
for InsetLayout.

Richard
Uwe Stöhr
2011-07-19 13:58:48 UTC
Permalink
Post by Richard Heck
I'm still hoping to do some major reworking of how arguments are
handled, i.e., get rid of that inset.
What do you have in mind instead? I have now a lot of experience with it and find the current
implementation acceptable, except of these 2 things:

- the menu entry must read "optional Argument, not "short title" (this is misleading and this
appears often at the users list that people are confused, a short title is only ONE occurrence of
optional arguments
- If there is a mandatory argument, the inset should appear directly when using the style and it
must not be allowed to delete this inset; this inset should have the label "req" (for required) and
not "opt".

Should I store thesesuggestions in an enhancement request?

regards Uwe
Richard Heck
2011-07-19 14:38:48 UTC
Permalink
Post by Uwe Stöhr
Post by Richard Heck
I'm still hoping to do some major reworking of how arguments are
handled, i.e., get rid of that inset.
What do you have in mind instead? I have now a lot of experience with
it and find the current implementation acceptable, except of these 2
- the menu entry must read "optional Argument, not "short title" (this
is misleading and this appears often at the users list that people are
confused, a short title is only ONE occurrence of optional arguments
It's much less clear how you can label different insets differently.
E.g., if there is one required argument and one optional one. Now what?
Post by Uwe Stöhr
- If there is a mandatory argument, the inset should appear directly
when using the style and it must not be allowed to delete this inset;
this inset should have the label "req" (for required) and not "opt".
This is bigger the problem. It's like with Bibitems, which are a mess.
You have to make sure no one deletes it, or moves it, or tries to type
in front of it. It's just not an inset.

The idea is to let arguments be typed into some sort of dialog, e.g., in
a new Arguments pane of the paragraph settings dialog. This is easy,
except for the fact that we want people to be able to type LyX, not
LaTeX, which means using the sort of embedded buffer that's used in the
advanced F&R dialog. That will take more work.

Richard
Jürgen Spitzmüller
2011-07-19 14:59:38 UTC
Permalink
Post by Richard Heck
Post by Uwe Stöhr
- the menu entry must read "optional Argument, not "short title" (this
is misleading and this appears often at the users list that people are
confused, a short title is only ONE occurrence of optional arguments
It's much less clear how you can label different insets differently.
E.g., if there is one required argument and one optional one. Now what?
And that's why it should not be labelled "optional" or "required argument",
but it should be semantically precise. "Short title" is (for the case the
inset was initially developed). "Longest label" is as well. LyX should tell
the user what this argument does, not just that it is an optional argument.
This is possible with some extended argument definition in the layout file.
Instead of

OptionalArgs 2

do something like

Argument
Type optional
Order 1
Label "Short title in TOC"
EndArgument

Argument
Type optional
Order 2
Label "Short title in header"
EndArgument
Post by Richard Heck
Post by Uwe Stöhr
- If there is a mandatory argument, the inset should appear directly
when using the style and it must not be allowed to delete this inset;
this inset should have the label "req" (for required) and not "opt".
This is bigger the problem. It's like with Bibitems, which are a mess.
You have to make sure no one deletes it, or moves it, or tries to type
in front of it. It's just not an inset.
Yes, this is not possible in a sane way with a collapsable inset.
Post by Richard Heck
The idea is to let arguments be typed into some sort of dialog, e.g., in
a new Arguments pane of the paragraph settings dialog.
Also consider that we already have this. "Longest label" in the paragraph
dialog is just another implementation of a specific (required) argument. We
just need to extend this concept.
Post by Richard Heck
This is easy,
except for the fact that we want people to be able to type LyX, not
LaTeX, which means using the sort of embedded buffer that's used in the
advanced F&R dialog. That will take more work.
Yes, but it's possible.

Jürgen
Uwe Stöhr
2011-07-19 16:54:48 UTC
Permalink
Post by Richard Heck
Post by Uwe Stöhr
- the menu entry must read "optional Argument, not "short title" (this
is misleading and this appears often at the users list that people are
confused, a short title is only ONE occurrence of optional arguments
It's much less clear how you can label different insets differently.
E.g., if there is one required argument and one optional one. Now what?
This is my second suggestion. To sum it up here in better words:

- When a style has a mandatory argument and th user use it, its argument appears automatically. This
inset can but must not be collapsible. The important thing is that is appears automatically and that
the user cannot delete it. As there is no choice to use it or not, we don't need a menu entry or not.
When a style has 2 or more mandatory arguments, the defined number of mandatory insets appears.

- the optional argument can sty as it is, only its menu entry in the Insert menu must be changed.


So assuming we have a command

\blahblub[alignment]{number of line}{width}

we define the style for it as follows in the layout file (in pseudo code):

Style
LatexName blahblub
Labelstring "BlaBlah: "
RequiredArgs 2
OptionalArgs 1
DefaultReqValue1 "1"
DefaultReqValue2 "1cm"
DefaultOptValue1 ""

When the style is used in a document you get this:

BlaBlah: |1||1cm|

where "| |" represents a required argument inset.

It is important that we can define a default value or mandatory arguments because some commands
don't like when there is no content in them. We therefore make a proposal to prevent that the user
forgets to insert something there. But the user can delete the default content when he like to keep
it empty for some reason.


I hope this is now clearer to understand what I have in mind.
Post by Richard Heck
The idea is to let arguments be typed into some sort of dialog, e.g., in
a new Arguments pane of the paragraph settings dialog.
This won't work because one must be able to insert all stuff to arguments. For example it must be
possible to use an equation, a figure or whatever as argument. There are commend who require this
(for example the package picinpar provides commands whost mandatory arguments are tables or figures).
Therefore the current implementation of the optional argument is already perfect (and one use TeX
Code with them too). So we only need a second inset for mandatory arguments with the same
possibilities in inserting stuff to it, but with the additional features I described above.

regards Uwe
Richard Heck
2011-07-19 17:33:45 UTC
Permalink
Post by Uwe Stöhr
Post by Richard Heck
Post by Uwe Stöhr
- the menu entry must read "optional Argument, not "short title" (this
is misleading and this appears often at the users list that people are
confused, a short title is only ONE occurrence of optional arguments
It's much less clear how you can label different insets differently.
E.g., if there is one required argument and one optional one. Now what?
- When a style has a mandatory argument and th user use it, its
argument appears automatically. This inset can but must not be
collapsible. The important thing is that is appears automatically and
that the user cannot delete it. As there is no choice to use it or
not, we don't need a menu entry or not.
When a style has 2 or more mandatory arguments, the defined number of
mandatory insets appears.
I understand the idea, but it would make the Bibitem mess look neat.
Post by Uwe Stöhr
- the optional argument can sty as it is, only its menu entry in the
Insert menu must be changed.
There can be more than one optional argument. Think about beamer.
Post by Uwe Stöhr
Post by Richard Heck
The idea is to let arguments be typed into some sort of dialog, e.g., in
a new Arguments pane of the paragraph settings dialog.
This won't work because one must be able to insert all stuff to
arguments. For example it must be possible to use an equation, a
figure or whatever as argument. There are commend who require this
(for example the package picinpar provides commands whost mandatory
arguments are tables or figures).
This is why you use an embedded Buffer, like with F&R.
Post by Uwe Stöhr
Therefore the current implementation of the optional argument is
already perfect (and one use TeX Code with them too). So we only need
a second inset for mandatory arguments with the same possibilities in
inserting stuff to it, but with the additional features I described
above.
As I said, I understand what you want, but it is not practical to do it
with insets.

Here's another idea I had, though I don't know how hard it would be to
implement. The idea would be to have "fake" insets. They would get drawn
like insets, but they would actually be attached to the paragraph and
wouldn't correspond to characters. You might think of them as existing
in the paragraph's margin.

Richard
Uwe Stöhr
2011-07-19 17:49:54 UTC
Permalink
Post by Richard Heck
I understand the idea, but it would make the Bibitem mess look neat.
What do you mean?
Post by Richard Heck
Post by Uwe Stöhr
- the optional argument can sty as it is, only its menu entry in the
Insert menu must be changed.
There can be more than one optional argument. Think about beamer.
Sure and it is no problem of allowing to insert more then one optional argument to a style. We
already have the infrastructure. What is missing is the layout code that allows to define more than
one optional argument. I would implement this the same way as in my example for 2 mandatory arguments.
Post by Richard Heck
Post by Uwe Stöhr
Post by Richard Heck
The idea is to let arguments be typed into some sort of dialog, e.g., in
a new Arguments pane of the paragraph settings dialog.
This won't work because one must be able to insert all stuff to
arguments. For example it must be possible to use an equation, a
figure or whatever as argument. There are commend who require this
(for example the package picinpar provides commands whost mandatory
arguments are tables or figures).
This is why you use an embedded Buffer, like with F&R.
But why not usig what we already have as optional argument inset. It allwas to insert there
everything the LyX way. And it is more intuitive than a dialog. Moreover a dialog would be a
restriction you don't see at one sight the different arguments and we need arguments for everything,
styles as well as InsetLayouts and LaTeX commands can be used for so many things we can not even
imagine.
Post by Richard Heck
Post by Uwe Stöhr
Therefore the current implementation of the optional argument is
already perfect (and one use TeX Code with them too). So we only need
a second inset for mandatory arguments with the same possibilities in
inserting stuff to it, but with the additional features I described
above.
As I said, I understand what you want, but it is not practical to do it
with insets.
Why not?
Post by Richard Heck
Here's another idea I had, though I don't know how hard it would be to
implement. The idea would be to have "fake" insets. They would get drawn
like insets, but they would actually be attached to the paragraph and
wouldn't correspond to characters.
It seems we are talking about different things. I want to have an implementation where I can define
styles for every sort of LaTeX commands with several optional and mandatory arguments. And no matter
if the LaTeX command represents a paragraph or not.

I do not need a special hack to attach something to a paragraph. This was a special issue I stumbled
over and why I started this thread. I think we already came yet to the conclusion that we only need
the same features for InsetLayouts as for styles. In the case which I started the discussion, the
problem would already be solved, if InsetLayout supports arguments like styles already do.

So my last two posts were about how to further improve the argument support.

regards Uwe

Liviu Andronic
2011-07-18 21:32:24 UTC
Permalink
Post by Uwe Stöhr
I often have the case that I need to define an inset that is internally a
LaTeX command. I use for this the Flex inset. But why does it not support
optional and required arguments. I mean it represents a LaTeX command, the
same way as a normal Style declaration.
Using
OptionalArgs            1
RequiredArgs            1
in a style works very well, but I need the same also for InsetLayout Flex:.
Can this be implemented or is this already available in another form?
I guess this is related to #6753 [1].
[1] http://www.lyx.org/trac/ticket/6753

Liviu
Loading...