@@ -236,11 +236,11 @@ font and its paragraph indentation.
236236
237237There are five behavioral properties of a style:
238238
239- * :attr: `~.Style .hidden `
240- * :attr: `~.Style .unhide_when_used `
241- * :attr: `~.Style .priority `
242- * :attr: `~.Style .quick_style `
243- * :attr: `~.Style .locked `
239+ * :attr: `~.BaseStyle .hidden `
240+ * :attr: `~.BaseStyle .unhide_when_used `
241+ * :attr: `~.BaseStyle .priority `
242+ * :attr: `~.BaseStyle .quick_style `
243+ * :attr: `~.BaseStyle .locked `
244244
245245See the :ref: `style_behavior ` section in :ref: `understanding_styles ` for
246246a description of how these behavioral properties interact to determine when
@@ -279,6 +279,74 @@ but allow it to remain in the recommended list::
279279Working with Latent Styles
280280--------------------------
281281
282- ... describe latent styles in Understanding page ...
282+ See the :ref: `builtin_styles ` and :ref: `latent_styles ` sections in
283+ :ref: `understanding_styles ` for a description of how latent styles define the
284+ behavioral properties of built-in styles that are not yet defined in the
285+ `styles.xml ` part of a .docx file.
283286
284- Let's illustrate these behaviors with a few examples.
287+ Access the latent styles in a document
288+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289+
290+ The latent styles in a document are accessed from the styles object::
291+
292+ >>> document = Document()
293+ >>> latent_styles = document.styles.latent_styles
294+
295+ A |LatentStyles | object supports :meth: `len `, iteration, and dictionary-style
296+ access by style name::
297+
298+ >>> len(latent_styles)
299+ 161
300+
301+ >>> latent_style_names = [ls.name for ls in latent_styles]
302+ >>> latent_style_names
303+ ['Normal', 'Heading 1', 'Heading 2', ... 'TOC Heading']
304+
305+ >>> latent_quote = latent_styles['Quote']
306+ >>> latent_quote
307+ <docx.styles.latent.LatentStyle object at 0x10a7c4f50>
308+ >>> latent_quote.priority
309+ 29
310+
311+ Change latent style defaults
312+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313+
314+ The |LatentStyles | object also provides access to the default behavioral
315+ properties for built-in styles in the current document. These defaults
316+ provide the value for any undefined attributes of the |_LatentStyle |
317+ definitions and to all behavioral properties of built-in styles having no
318+ explicit latent style definition. See the API documentation for the
319+ |LatentStyles | object for the complete set of available properties::
320+
321+ >>> latent_styles.default_to_locked
322+ False
323+ >>> latent_styles.default_to_locked = True
324+ >>> latent_styles.default_to_locked
325+ True
326+
327+ Add a latent style definition
328+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
329+
330+ A new latent style can be added using the
331+ :meth: `~.LatentStyles.add_latent_style ` method on |LatentStyles |. This code
332+ adds a new latent style for the builtin style 'List Bullet', setting it to
333+ appear in the style gallery::
334+
335+ >>> latent_style = latent_styles['List Bullet']
336+ KeyError: no latent style with name 'List Bullet'
337+ >>> latent_style = latent_styles.add_latent_style('List Bullet')
338+ >>> latent_style.hidden = False
339+ >>> latent_style.priority = 2
340+ >>> latent_style.quick_style = True
341+
342+ Delete a latent style definition
343+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
344+
345+ A latent style definition can be deleted by calling its
346+ :meth: `~.LatentStyle.delete ` method::
347+
348+ >>> latent_styles['Light Grid']
349+ <docx.styles.latent.LatentStyle object at 0x10a7c4f50>
350+ >>> latent_styles['Light Grid'].delete()
351+ >>> latent_styles['Light Grid']
352+ KeyError: no latent style with name 'Light Grid'
0 commit comments