Hi Riki,

thanks for the ideas - quite a few things I haven't really thought about.

Am 01.10.19 um 19:54 schrieb Richard Kimberly Heck:
>
> ...
>
> 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.



I've just analysed the available options:


a) If a label is put right at the start of a section in lyx, this gives:

Lyx-File:

.....
\begin_layout Section
\begin_inset CommandInset label
LatexCommand label
name "sec:MySection"

\end_inset

MySection
\end_layout
.....

and in exported tex-File:

.....
\section{\label{sec:MySection}MySection}
.....


This runs fine through my latex compiler, so I guess this is "proper"
latex code.


b) If a label is put it at the end of the section in lyx, this gives:

Lyx-File:

.....
\begin_layout Section
MySection
\begin_inset CommandInset label
LatexCommand label
name "sec:MySection"

\end_inset


\end_layout
.....

and in exported tex-File:

.....
\section{MySection\label{sec:MySection}}
.....

Works also as option a).



> 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.


c) The label is placed in the first paragraph past the section.

Lyx-File:

.....
\begin_layout Section
MySection
\end_layout

\begin_layout Standard
\begin_inset CommandInset label
LatexCommand label
name "sec:MySection"

\end_inset


blablabla ... more text ... blablabla

\end_layout

.....

and in exported tex-File:

.....
\section{MySection}

\label{sec:MySection}
.....


I guess option c) is what you recommend to avoid "bad Latex".


> So it's hard to tell what's meant to be a 'section'
> label.

I agree.

The good thing is - all variants run perfectly fine through my latex
compiler and generate the same result. So, maybe this "bad latex" thing
is more a style-issue, but not really a functionality problem.
Nevertheless, worth discussing.

With the current functionality, the user determines the insert position
manually before opening the "Create label" dialog.

When a label is now inserted automatically (new functionality), we
basically have two choices:

1. hardcode one of the options a, b or c
2. make option a, b or c a configurable option

I would be in favour of (1), and would only make this configureable if
users request it (avoid configuration option bloat), and further, I
would be in favour of option a (mainly, because that's how I write my
lyx documents :-)


Operation "check, which section/float has already a 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.

I would be worried about reliability of such an algorithm as well,
especially since we target a multi-lingual community which might use
"Kapitel:" instead of section.


Variants a and b would be fairly easy to detect (check if a label
CommandInset is inside the layout).

I would also implement the following rule: if more than one label
CommandInset is in a section layout, choose the first.

Variant c would be only realiably detected, if the following condition
is met: the layout following the section layout must start with a
CommendInset of type label -> if so, this label is accepted as existing
label for the section.


So what happens if the user has placed a label somewhere different?
Well, the new cross-reference dialog would not detect the label and
offer to insert a new one (in either of the locations discussed above).
Then, the document would possibly have two labels, but still would be
valid lyx and latex documents. IMHO, not a big problem here.


My proposal would be to agree on a "default" label placement position.

To get started with the implementation, I'm writing some code to detect
which section has a label.


Sorry for the long answer, but I guess if this were an easy ticket, it
would have been done already :-)

-Andreas

PS: Riki, thanks for the pointer to the outliner... need to check the
code there next!


Reply via email to