Insert First Word On Page Into Header

Is there any way to get the first word of a page and insert it into the header of that page? I’m working on a dictionary style document and am looking to have similar formatting to a dictionary with the current word(s) at the top of the page(s).

I assume I can achieve this with a macro or a regex, but I’m unsure if there’s an easier/preferable way to achieve this. Any help is much appreciated.

Headers don’t belong to single pages but to page styles. Therefore what you describe can’t be done .
If you want to change the header (or the footer), you need to create a new page style first.

I was thinking there might be a way to make a variable that can be inserted in the page style header, similar to how page numbers or other dynamic information is included.

There are several bugs related to variables and headers, see e.g. tdf#128041 and also serious limitations to variables themselves. Fields (type Set Reference) will not work because they can have only a single location. Variables cannot capture text and their current value will be used in the header, i.e. the last value in the previous page, not the next value in the current page (no forward scan).

The only way I see is to abuse the Heading n feature. But to give you a recipe, please edit your question to give an example of the formatting of your items. The recipe may need a change in the layout to make your specification work.

While you’re at it, mention OS name, LO version and save format. The trick I’m thinking of is valid only for .odt.

The textfield displaying the page number is extremely specialized.
IMO there will never be a feature reproducing its sensitivity to the position depending on page wrapping with a textfield showing user defined content.
To create a workaround based on custom code (in Basdic e.g.) using the header may be strictly impossible.

That’s a pretty advanced application of a word processor. Odds are that publishers of dictionaries use specialized software to achieve that kind of thing. For most cases, headers in documents made in the office will be used for repetitive text, and therefore, support for variable text on each page is very limited in word processors.
You may want to try something else. Like a frame without borders where the header would be. Make a special frame style where you set the values for position (vertical: from top, page text area, negative value, so that it overlaps the header area). You may be able to get them inserted on each page with a macro.

I don’t recommend using framesbecause (a) the process will be awfully manual (you never know for sure whare a page break occurs in a text-flow-oriented document, (b) the ordering of frames is not occurrence order but insertion-time order, which could lead to “funny” results.

I am waiting for a page layout example where we can see the defined term, the definition, examples and comments. I feel there is a very simple way to achieve OP’s specification by styling the defined term with some Heading n. Of course provisions must be made to avoid overflowing the TOC if any. OP should also tell if s/he has other headings like book divisions, parts, chapters, … The correct choice of n depends on this with a special case for the firsst page of a chapter because it is likely it doesn’t start with a defined terms unless chapter heading is laid out separately on an intermediate page with no other information.

You can probably forget about the Heading_n solution, because it’s well possible that the explanation of a term at the bottom of a page overflows to the next, so that the first actual term on a page is not in the first paragraph of that page.

I don’t think so because the very first paragraph belong to the last definition on the previous page. Therefore we really start the page with this previous word.
Of course if OP’s specification is to display the first possible term in the page there is no solution.

Let’s wait for update.

Sorry for the delay folks, been busy with the holidays.

Right now the each page is formatted to have 2 columns with a page number at the bottom. I do have Scrivener as well, so I might be able to achieve the formatting with that if not with LO. I was thinking this might be functionality present, if not, no worries.

Here’s some additional information as asked.
OS: Windows 11
LO: Version 7.2.4.1
Save Format: .odt

Thanks for this technical information, but what is really needed is the layout of your text. Something like ?


Defined term
<some_indent>Definition for the term¶


Or?
Defined term<some_tab>Definition for the term¶


The second case can’t be handled easily and requires a very contorted trick I don’t recommend to newbies.

The second is how we’re formatting the individual entries.

I don’t think it’s something that’s critical enough to implement a trick, just a nice to have someone asked about.

If you’re not intimately familiar with styles and fields, implement the first variant which is much simpler.
The term is in its own Heading n paragraph (choose n high enough to not interfere with your chaptering) or define a specific style attached to said level.
Set font face, size, weight, indents to fit your needs, Adjust space below to minimise spacing with definition. Enable Keep with next paragraph so that definition is never orphaned at bottom of page.
Create a style for the definition with required indent, spacing above to visually attach definition to term.

If you really want to have inline term and definition:

  • write the term in its own Heading n paragraph. Exact typographical attributes don’t matter as you’ll set Hidden in Font Effects.
  • In the definition paragraph:
    • Insert>Field>More Fields to insert the chapter name corresponding to your term
    • then type the definition
    • set the paragraph style properties for the definition
    • create a character style you’ll apply to the field to make the term bold, perhaps bigger, in a different font face; apply it to the term

      Note that the second variant requires more work than the first. Experiment to choose.

SkyEdwards,
you might have a go at the InLine Headings extension which is supposed to do exactly what you’re looking for.

Note that I’ve been reported a bug under Windows which, to date, I haven’t been able to reproduce in a Win10 VM. Might be worth a try, anyway.

I had a look at the InLine Headings extension. Well, I don’t like it. Not for its result which is correct but for its implication on the workflow. It is based on macros which must be triggered at some point. In particular, one must not forget to fire them before saving/publishing, otherwise headings may be inaccurate. Any change to heading styles or numbering is not immediately reflected in text and requires retriggering the extension.

On the bright side, this extension doesn’t use direct formatting but styling and removes its private character styles from the style side pane list to prevent fiddling with them.

I don’t like the “sentinels” around the inline headings. They are necessary to identify the additions so that they can be removed, but this is ugly.

The extension could largely be improved by use of cross-reference fields for the inlines.

Using cross-references (and some character styles) is the basis of the manual solution. It is much more tedious and error-prone than the extension but offers more versatility and, above all, allows automatic update of inlines should the headings be changed.

Here’s how I’m doing that:

  1. Give the dictionary entries a common style. Say DicEntry. In this style property dialog, Outline & list tab, give a Level to that style. I usually use level 10, since this level is not used anywhere else in the document.
  2. In the dictionary page header, insert a field (Document tab): Type Chapter, Format Chapter name, Level 10.
    And that’s it!

This is effectively the way to do it, but may not give the expected result, depending how the entries are formatted. This is why we’re waiting for more formatting or layout information from OP.

Do you know if there is a way to apply custom formatting, possibly with a formula or a regex of some kind? This solution works almost exactly how I need it to, I just need to isolate the first word. Since I have a coding background in my mind this is the easiest solution as I cannot change the formatting drastically at this point.

Some sudo regex thing:
=regex(“ Defined term <some_tab >Definition for the term”, “^([\w-]+)” )

a way to apply custom formatting

This usually means a user-defined style. Most common style categories are paragraph (acting on a full paragraph) and character (acting on a selected word).

In your case, select the “Defined term” and apply your character style (or built-in Strong Emphasis).

There is no such feature as your “regex” function. It is as fast to select the “Defined term” and apply a style as to modify your document with the tentative formula. Perhaps faster to apply a style.

Regex functionality does exist with Libre Office as far as the help documentation is concerned.

Since neither page indicates it doesn’t exist in writer, I assumed this functionality existed and was a matter of me just not understanding where to implement it.

I’ll try playing around with the styling a little more. I was trying earlier and couldn’t get it quite working how I wanted. I do understand how styling works to a certain degree, there’s just only so much I have approval to change in terms of the formatting and this is just a nice to have style.