Ask Your Question

Writer: clarification needed about character attributes

asked 2013-08-27 14:30:20 +0100

ajlittoz gravatar image

updated 2013-08-27 21:20:00 +0100

When using character styles, it is not clear whether the attributes changed by the style override or augment those of the paragraph style.

It is even more unclear if several character styles can be simultaneously applied on the same run of characters.

Take, for instance, "Source Text" which forces a monospaced font. If you subsequently apply "Emphasis", you end up with monospaced italic. On the contrary, if you apply a full user-defined style, then another user-defined style (with non conflicting attributes), the second style replaces the first one.

The (minor) consequence of this is: you'd better apply "Default" style first to be sure to have only the effects defined in the second style.

In addition to this forcing/augmenting dilemma, there is no notion of toggling attribute.

Say you want to emphasise a sequence with "Outline" (I know it is ugly, but this is for a simple example). You can easily define a style forcing outline character shape. Now, your paragraph uses outline by default and you want to emphasise a single word by negating "Outline" style. In my LO experience, I do that only by defining a new style "Removed Outline" where I force the absence of the effect. I end up with 2 paragraph styles and I must care to explicitly use the right one. Moreover, if I change my mind afterwards with style "Outline", I must manually replace all "Removed Outline" style with "Outline".

The situation is even more complex with basic stylistic variations like italic or bold.

These variations are in fact different typefaces in the same font family. Consequently, "toggling" is meaningless. Setting or unsetting italic is equivalent to chosing a different font.

Coming back to the previous example, how to toggle italics in an italic-default paragraph without defining 2 context-dependent character-styles?

To sum up my concern, attributes can be forcing (0 ou 1), toggling (logical xor) or augmenting (logical or).

What is the underlying model in LO? Is it consistent?

edit retag flag offensive close merge delete



Your question is very important and I have been investigating such issues for some time. I think that ideally, what we’d like is a system that behaves consistently and intelligently the way a system like LaTeX does (I’m pretty partial about LaTeX, but I strongly believe in LibO’s potential too ;-) ). For example, how can we get a conditional emphasis character style dependent on the underlying paragraph style?

CyanCG gravatar imageCyanCG ( 2013-08-28 23:36:48 +0100 )edit

I’ll try to come up with a decent answer to your question in a few hours, stay tuned. This is a good opportunity to write a small summary of “my understanding so far”.

CyanCG gravatar imageCyanCG ( 2013-08-28 23:37:24 +0100 )edit

2 Answers

Sort by » oldest newest most voted

answered 2013-08-29 04:12:03 +0100

oweng gravatar image

updated 2013-08-31 02:06:13 +0100

I am sure @CyanCG will provide a good answer here, but what I am commenting on is (IMO) one related aspect of why this character vs paragraph style override (OR / XOR) exists. The v3.5 series of LO did not abuse usage of the <text:span> element to the same extent as the v4.x series do. The ODF specification v1.2, with respect to this element, states:

6.1.7 <text:span>

The <text:span> element represents the application of a style to the character data of a portion of text. The content of this element is the text which uses that text style. The <text:span> element can be nested.

Here is a brief example of how use of this element has become problematic. Under GNU/Linux running TDF/LO v4.1.0.4 these steps produce the indicated underlying XML (double quotation marks are not entered, but are merely indicative of text to be entered):

  1. Open Writer.
  2. Enter "Here is some text."
  3. Save as a1.odt and exit Writer.
  4. XML shows:

    <text:p text:style-name="P1">Here is some text.</text:p>

  5. Re-open a1.odt.

  6. At the end of the previous text enter " It is now set to Text Body paragraph style."
  7. With the cursor still at the end of the text double click on the Text Body paragraph style.
  8. Save as a2.odt and exit Writer.
  9. XML shows:

    <text:p text:style-name="Text_20_body">Here is some text. <text:span text:style-name="T1">It is now set to Text Body paragraph style.</text:span> </text:p>

  10. Re-open a2.odt.

  11. At the end of the previous text enter " Same paragraph, but now I am going to go back and italicise the name of the style."
  12. Highlight "Text Body" and set it to use the Emphasis character style.
  13. Click at the end of the text and continue typing " I used the character style ‘Emphasis’ to do so and continued typing here afterwards."
  14. Save as a3.odt and exit Writer.
  15. XML shows:

    <text:p text:style-name="Text_20_body">Here is some text. <text:span text:style-name="T1">It is now set to </text:span> <text:span text:style-name="Emphasis"> <text:span text:style-name="T1">Text Body</text:span> </text:span> <text:span text:style-name="T1"> paragraph style. Same paragraph, but now I am going to go back and italicise the name of the style. I used the character style ‘Emphasis’ to ...

edit flag offensive delete link more


I do agree that simplicity in XML structure eases things and facilitates later updates. How does such a regression (personal opinion, no offense intended) happen? Some feature addition?

I don't understand the translation of a2.odt editing: a1 paragraph was "Standard". Adding text at the end uses the styles active at that location (in my understanding). Setting "Text Body" should style the whole paragraph content unless 'Revision tracking' is enabled by default (or at least some hidden feature gives the possibility to regenerate the revision history).

I already noticed user-visible differences between 3.x and 4.x. This fundamental one makes me hesitate to switch to 4.x for production.

ajlittoz gravatar imageajlittoz ( 2013-08-29 08:36:47 +0100 )edit

@oweng, this sums up the XML aspect very well. I’ll try to account for what happens inside the application itself, i.e. in LibO’s internal data structures (at least, the part of them that I think I understand). The abuse of span elements with automatic styles in 4.0 and 4.1 troubles me very much, among other reasons because it makes conversion to other XML formats (XHTML) and TeX formats (LaTeX, ConTeXt) much less clean and less semantic.

CyanCG gravatar imageCyanCG ( 2013-08-29 16:01:04 +0100 )edit

My memory is failing me, but I read somewhere (Bugzilla? new release feature page?) that this new use of span elements was meant to facilitate interoperability with OOXML: indeed, in Microsoft’s format, all text portions of a paragraph are part of something called a text run, even if no special formatting is applied to them (one of the many reasons why this format is awful). It might be related to change tracking. In any case, I don’t think this is a good reason to abuse span’s.

CyanCG gravatar imageCyanCG ( 2013-08-29 16:05:30 +0100 )edit

I agree with all your comments and I too find this matter of <text:span> elements troubling. ISO/IEC 29500-1:2012(E) § on p.293 outlines the <w:r> (Text Run) element. I can understand that <text:span> is used as a way of mapping to this element to cater for interoperability, but the behaviour of adding to existing text should not necessitate this. It should be checked whether the element is required. I cannot find a related bug or information on this change from v3.x to v4.x.

oweng gravatar imageoweng ( 2013-08-30 01:40:05 +0100 )edit

Update: I found a related LO User ML thread which points to a related bug: fdo#68183. Unfortunately the answer appears to be related to revision tracking (the officeooo:paragraph-rsid property, which is what @CyanCG suggested i.e., it is a OOXML compatibility feature). In my examples above I did not have revision tracking turned on, so I would think this unnecessary.

oweng gravatar imageoweng ( 2013-08-30 01:53:37 +0100 )edit

This is the bug I had in mind. The comment by Holger Schmithüsen nails it pretty well. Who do we need to convince to see this bug adressed? This officeooo:rsid attribute is a hack and is absolutely unnecessary for those who actually use the OpenDocument format because of its specific virtues. I think that’s how the issue should be presented. OOXML compatibility should never have negative side-effects for those who choose ODF.

CyanCG gravatar imageCyanCG ( 2013-08-30 21:39:02 +0100 )edit

Well, I did a bit more research and it appears I was wrong in my initial conjecture that this was an OOXML-related change. The change relates to the feature for comparing documents. I have updated my answer to be clearer about this. Bug fdo#52028 provides the details. This is still little comfort if you would like the underlying XML to be cleaner. All I can suggest is raising a bug to address this, but unfortunately you will need to be incredibly specific in your detail of the problem.

oweng gravatar imageoweng ( 2013-08-31 02:10:15 +0100 )edit

Good, at least this appears to be a better reason for introducing those rsid’s. I might eventually raise a bug and describe the rationale, the use cases, the best practices etc. Maybe I’ll ask for advice on TeX.SE first by asking a question along the lines of “is it advisable to define \newcommands for marking up subsequent additions and revisions to a document?”. That would give us some food for thought!

CyanCG gravatar imageCyanCG ( 2013-08-31 15:22:34 +0100 )edit

answered 2013-08-31 16:12:05 +0100

CyanCG gravatar image

updated 2013-09-03 16:57:01 +0100

Applying more than one text (character) style to a portion

I am using LibreOffice 4.1 on OS X 10.8.

It is indeed possible to apply more than one character style to a given portion of text. Take the following example with the two styles you mention (Source Text and Emphasis):

<text:p text:style-name="P1">This is what
<text:span text:style-name="T1">emphasized </text:span>
<text:span text:style-name="Source_20_Text">
<text:span text:style-name="Emphasis">code</text:span></text:span>
looks like.</text:p>

In this first example, I have added the string emphasized afterwards, so that it is enclosed in its own span element with an automatic text style T1. Reminder: styles that apply to text strings are called character styles in LibO and text styles in the ODF spec. The T1 style is defined thus:

<style:style style:name="T1" style:family="text">
  <style:text-properties officeooo:rsid="000c8b60"/>

The only defined attribute is an officeooo:rsid, which shows that this style’s only purpose is document comparison (this makes me grumpy). Apart from that, we can see that it is quite possible to apply two character styles to the same portion. In fact, there are two ways to say it:

  • LibO speak: It is possible to apply multiple different character styles to one text portion;
  • Spec speak: It is possible to enclose a given text node in multiple nested span elements with different text:style-name attributes.

Remark on LibO’s behaviour: the effects are cumulative, so that the word code in this example is displayed in monospaced oblique type (for a monospaced font, the proper term is oblique, as there is no italic shape to speak of, but of course LibO does what is expected and chooses the oblique font).

Remark on implementation: according to the ODF 1.2 spec (part 1, section 19.770), a text:class-names attribute exists for the purpose of applying more than one text style to a node:

A text:class-names attribute specifies a white space separated list of style names. The referenced styles are applied in the order they are contained in the list.

If both text:style-name and text:class-names are present, the style referenced by the text:style-name attribute is applied before the styles referenced by text:class-names attribute. If a conditional style is specified together with a text:class-names attribute, but without a text ...

edit flag offensive delete link more



@CyanCG: Congratulation for the depth of this answer

  1. Character styles are cumulative ("or" in my wording): then how do we remove an attribute, like contour? (I don't take bold since font family may come with several bold values, e.g. Univers). Re: your remark about conditional emphasis.
  2. My usage of character style is close to semantic markup. I experiment afterwards with visual attributes in the style definition until the distinctions are "visible" (simultaneously trying to keep the traditional typographic usages).
  3. Ergonomics: from a user point of view, there should be some highlighting in the style navigator to show which character styles are active in the selection, not the last (?) one only (the StarBasic hack is not a solution). Presently ...
ajlittoz gravatar imageajlittoz ( 2013-08-31 18:08:43 +0100 )edit

I agree, and my solution for now is also to apply “Default” and then re-apply the style I really need. If a single attribute is removed with direct formatting (an automatic style in the spec terminology) then it takes precedence over any applied style (be it user-defined or application-defined). That complicates things further.

CyanCG gravatar imageCyanCG ( 2013-08-31 23:12:06 +0100 )edit

Terrific analysis with which I agree. A few small things (all near the beginning): "the string emphasis afterwards" should read "the string 'emphasized' afterwards"; near the bullet points perhaps "multiple character styles" rather than "two character styles" (twice); rather than "slanted" I think the correct term is "oblique". The commentary about reverting to Default formatting and direct format overrides I also agree with (in despair). I too cannot obtain text:class-names from testing.

oweng gravatar imageoweng ( 2013-09-01 02:59:05 +0100 )edit

Answer amended. Slanted is also in common usage, but the article on Wikipedia suggests that oblique is indeed the preferred term :-).

CyanCG gravatar imageCyanCG ( 2013-09-03 16:59:14 +0100 )edit
Login/Signup to Answer

Question Tools



Asked: 2013-08-27 14:30:20 +0100

Seen: 988 times

Last updated: Sep 03 '13