# Re: Proposal for UI enhancement: ticket #1624


Sorry to top post, but since this isn't a response to anything
particular....

I do still have some worries of the sort I expressed at
https://www.lyx.org/trac/ticket/1624#comment:11. A label for a section
really shouldn't be in the section heading itself, from a LaTeX point of
view, though it's natural to put it there in LyX. There's been some
discussion of automatically moving such labels to right after the
\section command. But, now, many users don't put them in the heading, so
as not to generate bad LaTeX. Maybe they put labels at the beginning of
the first sentence. So it's hard to tell what's meant to be a 'section'
label. Possibly we could use the prefix to determine this ("sec:" in
this case), though any such algorithm will be error-prone. So it's not
that easy to tell if a section 'already' has a label.

Contradicting my former self, I think it would be best to skip this sort
of check and just have some mechanism through which one could "create a
label" for some pre-existing section, etc, which would be automatically
inserted at an appropriate point, and return you to the cross-ref dialog
with that reference pre-selected. That does make me wonder, along with
my former self, whether a clean way to do it would not be just to add
this "Create label..." functionality to the outliner, and add a button
to the cross-ref dialog that would, in effect, open the outliner, or put
the focus there if it already is open. The dialog, after all, will need
to look very similar. At the very least, though, you can get a list of
the sections, etc, that exist from the outliner backend.

Riki

On 9/29/19 7:34 AM, Andreas Nicolai wrote:
> Hi Scott,
>
> thanks for your ideas, let me comment below.
>>> I would like to contribute an improvement on this workflow:
>>> 1. Button and sub-dialog approach:
>>> - add a button on the dialog "Create label"
>>> - sub-dialog opens and allows selecting existing
>>> sections/subections/images/tables in a tree-view or filtered list-view
>>> (with combo-box filter)
>>> - if a label exists for this section -> close dialog using button
>>> "Select label"
>> It feels like there's an inconsistency here. At this point, the user has
>> clicked on "Create label". But for this situation (the label already
>> exists), there is no label that is created. I wonder if "Cancel" would
>> be the correct choice by the user if they want to use a label that's
>> already been created. Alternatively, perhaps my concern would be
>> addressed by renaming "Create label" to something else (I don't
>> currently have a suggestion).
> Indeed, "create label" might be misleading. Actually, the button spawns
> the regular "Insert label" Dialog (class GuiLabel). When confirmed, the
> user has effectively inserted a new label at the selected section/float.
> Maybe "Insert new label" or so might be better (actually, this modal
> "sub-dialog" variant isn't really my favourite).
>
>>> - in cross-reference dialog update list of labels and select newly
>>> created/selected label
>> Why do we need this step? i.e., why not directly insert the label just
>> created? I'm guessing it is because the user might want to change
>> something else in the cross-reference dialog, such as the "Reference
>> Format", but I just wanted to check that that's what you have in mind.
> Correct, that was my intention. After the label-selection normally one
> may adjust the reference format (actually, in my experience this happens
> only often when writing text with equation references and section/float
> references).
>
>
>>> 2. "switch selection list"-appraoch:
>>> This facilitates also the approach when users are not 100% sure which
>>> section to reference right now or when the choosen labels are not 100%
>>> clear in what they describe. In such cases the document structure and
>>> section captions can be a better way to select labels.
>>>
>>> Idea: the cross-reference dialog has two selection modes:
>>> a) as before, a groupable, filter-able list of existing labels
>>> b) a groupable list of all existing sections/subsections/images/tables,
>>> with highlighting (bold-face) for all list items that have already
>>> labels defined
>>>
>>> User can switch between both views via
>> Interesting ideas! Just to be clear, instead of "images" I think you
>> mean "figure floats".
> Right. But in the tree view/list I would still distinguish between
> Graphics and Tables, since IMHO authors rather think in terms of
> Image-reference and table-references when writing text (such as "see
> Fig. \ref{fig:xxx}" or "in Table \ref{tab:xxx})".
>
>> And perhaps instead of "figures/tables" we can
>> generalize to "floats". I don't understand variant 2 well.
> Actually, variant 2 is pretty much what you would expect from a regular
> text processor. You (the author) type text where a reference might be
> needed/appropriate. For example: "This is the same as discussed already
> in section ". Now, you want to insert a referece. You hit the shortcut
> for "insert reference" and a dialog appears. Here, you select the
> section in question, click ok and go on typing. The selection of the
> section is hereby done based on the caption or number and caption, for
> example "2.3 Equations that yield 42", just as it appears in the
>
> Since the current functionality is also needed (select label by label
> name), the "select by reference text/number" approach would work better
> for quite a few authors.
>
> Remains the question on how to actually generate the new label name and
> where to insert it.
>
> For may insets a default behaviour could be formulated:
>
> - sections/subsections... : always insert the label right at the begin
> of the inset, before the caption text
>
> - figures/tables/floats in general: always insert the label at the begin
> of the caption text
>
> - listings: require caption to create new label, if caption is present,
> use as for regular floats.
>
>> An extension that might be worth talking about later: currently, does
>> LyX know how to add a label for different layouts? It might, I don't
>> know. In any case, perhaps we would need some layout tag that would tell
>> LyX how to add the label. For example, if a user creates a new layout
>> how does LyX know where to put the \label command? Should it put it in
>> one of the arguments or in the main chunk? I don't know much about
>> LaTeX. Perhaps this isn't needed at all.
>> I would
>> suggest waiting until another dev comes along and gives a strong signal
>> for you to go forward spending more time on this.
>
> Sure, right now I'm still analysing the inset-creation code and try to
> figure out, how the "GuiLabel" dialog actually works.
>
> For (my favourite) variant 2, I still don't know what would be the best
> way of switching between the "selection modes". My best bet so far is to
> use a tab widget with horizontal tabs saying "Select by label", "Select
> by caption"
>
>
> Any ideas are welcome!
> -Andreas
>