Automatic three-letter initials on header in dictionary

Hi

I’m using Libreoffice Writer with the following specifications.
OS: ubuntu 18.04.10
LO version: 6.0.7.3

I’m writing a historical glossary. At the moment it contains 946 entries, but the number is constantly growing. I have an interesting question for all you libreoffice lovers.

The chapter containing the entries has a very simple structure. There is a section of 2 columns, useful for compacting the text. I’m using the Text body style throughout the chapter and make the entries bold, but the style is still the same, only one.

It would be amazing to have a triletter abbreviations in the header which indicate the first and last entry of each page (look at my screenshot below) to improve the quality of the book. Is there a system to automatically create these acronyms in the header or is it necessary to do it manually?

Entering this detail by hand is impractical, because the dictionary is constantly evolving, not only as you add or change entries, but also as you revise fonts and margins. The clueless solution is to wait at the end and do it by hand. But then, when it’s time for the second edition, everything will have to be repeated anyway.

I show you the screenshot of the page 18 (it is cropped but it doesn’t matter), if you think it’s necessary I can also share part of the source file, but it doesn’t seem essential to me.

Thanks a lot.

To give you advice, we need more information about the structure of your book. So edit your question to improve it. Be kind to contributors by not adding details in comments but by really editing your question. This is not a forum but a Q&A site where questions, comments and answers are always editable.


Start by the usual technical details: OS name, LO version and save format.

Next how do you format your glossary? An automatic solution will be based on styles. So which styles do you use? Have you a separate paragraph for the entry name and another one for its definition. Which styles for each?

Ideally, attach a 1-page sample so that we can analyse the structure, understand it and suggest improvement/solution.

What I’m thinking of, if it is possible in your case, would insert the first entry in the header and the last entry in the footer.

Ok, thanks. I introduced several details and an image. I think it’s much clearer.

In your current layout, there is no solution. The idea is to have two paragraphs per entry: first paragraph containing only the term; second paragraph containing the definition. Then the paragraph can receive different paragraph style. In particular, the first paragraph can be assigned one of Heading n, which can then be automatically captured in the header.

Attach a 1-page sample so that I can modify it to show you the principle.

First of all, thank you for your interest and participation.

Personally, I think it’s not worth it, it becomes manual work.

If I have to assign two paragraphs for each entry, it means investing a lot of time, but I tell you that I would also be willing to do it.

But if I have to assign another style to the first entry, so that it can be recognized and shown in the Header, I would say that it is not good. In fact, if I insert a new entry, then everything will move and will no longer be valid. What was previously the first entry on page P will become the second or third, it depends.

I realize that for a processing like this it is necessary to develop an algorithm and processed it. It seems to me the only sensible solution. Does working with “UNO” allow me to solve the problem?

Usually people think “macros” before thinking about built-in features. Macros are the serious inconvenience they must be “triggered” to make their effect. On the contrary, built-in features are closely integrated with the formatting and lay-out engine and require no manual intervention.

The idea I have in mind is quite simple and is similar to what you do to show the chapter name in the header. It is fully automatic. When you add a new chapter or move an existing one, the header is automatically updated to show the current state of the document.

The feature looks at the state in the first paragraph in the page. It retrieves the chapter number+name, sub-chapter number+name, down to level 10. In the header, you insert a field requesting a specific level.

To show you how simple this is, please attach a 2-page sample (2 pages so that you can see the change on page 2). I’ll restyle the sample according to the built-in feature. And I can even return two variants: one with first entry in header and last entry in footer; the second one a bit more complicated with first and last entries in header (with a cheat trick).

Of course I can attach a sample. But before you invest any more time working on the file, I’d like to ask you two simple technical questions that you can answer very quickly (I assume).

  1. Isn’t it possible to show two distinct entries in the header?
  2. Is there any way to extract part of the entry?

Thanks

Yes and no, it depends on how and where they where captured.

No. The capture is displayed “as is”

Showing you the model is only a matter of a quarter of an hour.

2 pages sample
ggg.odt (18.6 KB)

The key to the solution is adequate styling which your sample does not meet. You have direct formatting which promotes visual appearance while your problem calls for semantic markup, i.e. a style flags a semantic usage allowing to make a distinction between similarly looking sequences.

I started by breaking your glossary entries into two paragraphs so that the significance of each can be properly advertised: the term itself (from which I removed the “bold” direct formatting) as Heading 10 and the explanation as Definizione. Note that I didn’t remove the various direct formatting from the explanation, generally italics which have two purposes: emphasis on a new word or cross-reference to another entry. These are two different semantic values and should receive two different character styles (one being possibly built-in Emphasis).

I played with the Text Flow parameters of both styles (Keep with next paragraph and widow/orphan controls) so that a term is never separated from its explanation by a page break.

I used Heading 10 because it is available but you can use a user paragraph style attached to some outline level. Remember you can limit the depth of the TOC so that level 10 is not collected.

I then enabled the header in the various page styles of the glossary. Since you use built-in Left Page and Right Page, it is likely they are also used in other chapters than the glossary. As the header contents is specific to the glossary, You should also use specific user page styles in your glossary so that the chapters don’t show glossary headers (which anyway would be wrong because the chapters have not been prepared for the specific information). I let you do that.

We’re now ready to add data into header and footer.

Glossary-variant A.odt (18.7 KB), the simplest but not conforming to your specification

In the header, Insert>Field>More Fields, Document tab, Type Chapter, Format Chapter Name, Level 10 (corresponding to Heading 10). Writer captures the state of the first paragraph in the page and uses this information to insert the requested chapter heading.

Note it does not work on the first page because the first paragraph is a Heading 2 and although the request is for level 10, this level 10 does not exist at this position and level 2 is reported. More on that later.

In the footer, the same field is inserted to capture the state in the last paragraph. There is no problem here.

I noticed you also applied direct formatting in your footer. Don’t do that, Footer paragraph style default configuration is versatile enough to not need any direct formatting.

Glossary-variant B.odt (19.0 KB) where first and last entry are both in the header

As mentioned, Writer determines the outline state either at start of page or at end of page. There is no way to tell it to forward scan the page to retrieve the state and anyway the fields will report only the current state (you can’t request some other state than the current one). Consequently, what is known in the footer should be sent “visually” or "apparently into the header despite the fact that the data is generated in the footer. This is possible with a frame. The frame will get its information from its anchor but will be moved into the header.

I create a dedicated frame style names Last entry for the purpose. It is anchored To paragraph in the footer but moved upwards through its Position parameters. I chose the Page text area reference. It makes it easy to position the frame at right of header. Vertical position is a bit more tricky and you’ll have to adjust it it you change your header geometry in the page style. For ease of formatting I used Header paragraph style inside the frame so that contents will also be updated in case you change Header.

Glossary-variant C.odt (19.1 KB) addressing the issue of the first page

As mentioned earlier, the initial outline state is determined from the first paragraph in the page. Your glossary starts with its Heading 2. Consequently, what is captured is levels 1 & 2 and nothing else because at this point there is no deeper level. The solution is to force beginning of the glossary on a new page with a manual page break in the first entry. This means the glossary heading is left alone on its page. You could then format it in the center of the page like we see in some books where part (subdivision/volume) heading has a specific. layout different from chapter. I let you do that.

Side remark: you forced First Page built-in page style at start of your glossary (and I assume you did the same in your other chapters). This is not the intended usage of this style. As the name implies (badly), it is the very first page of the book, the cover page. You could have a simpler solution by unticking the check boxes in the Header and Footer tabs of the chapter and glossary page styles.

Thank you very much. You’ve done a great job, what previously seemed achievable only in another galaxy is now here in front of me.

As for how to show the 2 entries in the header, that’s fine too. Perhaps your graphic solution (versions B and C) is even better than mine, which only wanted the first 3 letters.

You have already given me a lot of information and transmitted concepts that I am learning and will learn in the next few days. I can’t learn everything quickly.

I ask you a question. You have opted for the solution of showing the chapter in the header, this works but there is the problem of the first page of the chapter. Leaving the first page blank is a not too elegant workaround, I could think of writing a short introduction on the first page. But instead of showing the chapters in the header, can’t you take the first and last reference on the page? Or another solution that frees us from having to take the chapters?

As I explained this is a consequence of a limitation in Writer. When you’re at the top of page, Writer does a limited forward scan to the very first paragraph in the page. This paragraph has a certain position within the outline. It can be a Heading n paragraph, in which case it is easy to retrieve information about heading and numbering up to and including level n. Levels n+1 to 10 will be void and return the highest defined contents, i.e. the one for level n. It can also be a text body paragraph. But the current outline is known and the previously described algorithm is applied.

Then you know exactly the context of the very first line in the page. There is absolutely no way to request the state in the middle of the page.

There is no problem at end of page (in the footer). In this position, there is no need to scan because you’re looking “backwards” to the very last word/character in the page. You retrieve the state the same way as described above.

Let’s come back to the start of your glossary. It begins with a Heading 2. According to the algorithm, the captured state corresponds to level 2. As I said, there is absolutely no way to request a scan to the next Heading 10 (which in most documents don’t exist). Such a scan could be possible only after the full page has been laid out and this could cause terrible text flow issues. In the extreme case, some placeholder for the future Heading 10 contents has been reserved but when contents is known in the end, this placeholder could be either too large or too narrow, causing text reflow which could change page contents and either move the Heading 10 on next page or bring in another Heading 10 from next page, breaking everything which was tentatively composed.

The present, rather static, behaviour represents IMHO the best tradeoff preserving both text contents predictability and performance.

So we have to live with the fact that the first Heading 10 field insertion in fact returns *Heading 2 contents. This is why in variant C I suggest to leave the glossary heading alone in its page and to start the effective glossary after a page break.

Writing an introduction after the glossary heading is an excellent way to mitigate the somewhat “strange” look of the first page. This introduction is of course laid out in the single-column page and you can even assign it a specific paragraph style with larger indents (increased margins) and large spacing above to make it clear it is a kind of comment about what follows. You can even set the font to italics to emphasise more on the comment significance.

The first reference could be inserted in the first page header as a cross-reference to a heading. However, this idea has several weaknesses.

  • it is not an automatic solution and you must specifically designate the “first” term among the headings; this means that if you add a new “first” item before the current one, you have to reinsert the field and delete the previous one
  • similarly, you could pick the “last” item and insert it as a cross-reference into the header, but the solution exposed in my samples is much more reliable; the reason is the same as previously: you don’t know for sure which item is the last in the page (pages are not primary objects in Writer, they are allocated on demand to accommodate text); consequently, edits could move the designated item which would no longer be the “last” in the page

And if you try this in the running pages (not the first one), it will not work because any page style can have only one header and one footer. Using cross-references to paragraphs makes a static header which is repeated the same all over the pages. Using “document” properties like chapter name creates a dynamic header whic adapts its contents to the current state.

So, apart from isolating the first page, making it a bit special, I see no solution conforming to your specification.

I didn’t understand everything, because I have gaps with some tools that I will be able to fill, but I trust what you write.

I totally understand the concept of static and dynamic values.

When I go to Insert > Fields > More fields I get a screen divided into 6 sections.
Document | Cross-references | Functions | Docinformation | Variables | Database

I understand that only from Document and Docinformation it is possible to obtain dynamic management in relation to content of the file. Am I correct?

A solution to my problem could be to insert entries for the creation of the alphabetical index and then be able to obtain the first and last one in the header. However, it seems to me that this functionality is not provided because it was designed for another use. Right?

Partially. DocInformation returns data stored in File>Properties. They are “static” because they can have only one value across the document. Only fields from Document allow to return “context-sensitive” data like current chapter name and number or page number. The others seem to me rather static.

Show variable in Variables is also “dynamic” because it returns the current variable value but it is difficult to use it in header because I discovered a nasty bug in some circumstances.

No. An alphabetical index has not the same usage as a glossary. You would have a lot of pain to set up your entries for the alphabetical index and perhaps you would suppress the page number if what you want is to mimic the glossary. In addition, there is no way to capture the first and last entry in an index page. All you can do is to auto-insert (this is a parameter in the alphabetical index configuration) an initial (usually a letter unless your index entry begins with a symbol and this symbol will be used as separator) between blocks starting with the same symbol. The separator has a specific paragraph style and thus can be formatted in any way suitable to show the break in the index.