### Extract Plain Text with Wordometer Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Use `extract-text` to get plain text from Typst content. It can also exclude specific elements like strong text. ```typ #import "@preview/wordometer:0.1.5": word-count-of #import "@preview/wordometer:0.1.5" as wordometer #let content = [Hello *world*, this is _formatted_ text!] // Extract plain text (available via utils) #let plain = wordometer.utils.extract-text(content) // Returns: "Hello world, this is formatted text!" // Use with exclusions #let plain2 = wordometer.utils.extract-text( [One *bold* two], exclude: (strong,) ) // Returns: "One two" ``` -------------------------------- ### Basic Word Count Usage Source: https://github.com/jollywatt/typst-wordometer/blob/master/README.md Import the word-count and total-words functions to display the total word count in the document. ```typ #import "@preview/wordometer:0.1.5": word-count, total-words #show: word-count In this document, there are #total-words words all up. #word-count(total => [ The number of words in this block is #total.words and there are #total.characters letters. ]) ``` -------------------------------- ### Calculate word statistics programmatically Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Retrieve a dictionary of statistics for specific content without rendering it to the document. ```typ #import "@preview/wordometer:0.1.5": word-count-of #let content = [Hello world! This is a sample text.] #let stats = word-count-of(content) // Returns: (words: 7, characters: 29, sentences: 2) Word count: #stats.words \ Character count: #stats.characters \ Sentence count: #stats.sentences // With exclusions #let stats2 = word-count-of(exclude: strong)[One *not counted* two three.] // Returns: (words: 3, characters: 11, sentences: 1) ``` -------------------------------- ### Perform global and scoped word counts Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Use word-count as a show rule for global document statistics or with a callback function for scoped counting. ```typ #import "@preview/wordometer:0.1.5": word-count, total-words, total-characters // Global word count - use as a show rule #show: word-count This document contains #total-words words and #total-characters characters. // Scoped word count - use with callback #word-count(total => [ This paragraph has #total.words words and #total.characters characters. ]) ``` -------------------------------- ### Define custom counting logic Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Implement custom counter functions to track specific patterns or text properties by returning a dictionary of counts. ```typ #import "@preview/wordometer:0.1.5": word-count-of, word-count // Count vowels and five-letter words #let content = [Lorem ipsum dolor sit amet.] #word-count-of(content, counter: text => ( vowels: lower(text).matches(regex("[aeiou]")).len(), five-letter-words: text.matches(regex("\b\w{5}\b")).len(), )) // Returns: (vowels: 9, five-letter-words: 3) // Use custom counter in scoped word count #word-count(total => [ ABCDEFGHIJ has #total.vowels vowels. ], counter: text => ( vowels: lower(text).matches(regex("[aeiou]")).len(), )) ``` -------------------------------- ### Count specific document sections Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Apply scoped show rules to aggregate word counts from multiple distinct sections of a document. ```typ #import "@preview/wordometer:0.1.5": word-count, total-words This preface is not counted. #[ #show: word-count One two three four. ] This interlude is not counted either. #[ #show: word-count Five six seven eight nine ten. ] Total words in counted sections: #total-words // Displays: 10 ``` -------------------------------- ### Access word count state for calculations Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Use the wordometer state variable to perform conditional logic or progress tracking based on current word counts. ```typ #import "@preview/wordometer:0.1.5": word-count, total-words #show: word-count #lorem(100) #context { let target = 500 let stats = state("wordometer").final() let words = stats.words let percentage = calc.round(words / target * 100, digits: 1) [Essay progress: #words / #target words (#percentage% complete)] if words < target { [\ #text(red)[Need #(target - words) more words!]] } else { [\ #text(green)[Target reached!]] } } ``` -------------------------------- ### word-count-of Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Returns a dictionary of word count statistics for specific content without displaying it in the document. ```APIDOC ## word-count-of ### Description Calculates statistics for a given content block and returns them as a dictionary. ### Parameters #### Request Body - **content** (content) - Required - The Typst content to analyze. - **exclude** (selector/array) - Optional - Elements to exclude from the count. - **counter** (function) - Optional - Custom logic for counting specific patterns or properties. ### Response #### Success Response (200) - **words** (integer) - Total word count. - **characters** (integer) - Total character count. - **sentences** (integer) - Total sentence count. ``` -------------------------------- ### Word Count with Figure Handling Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Wordometer allows specific handling of figures for word counting. You can exclude figure bodies or captions independently. ```typ #import "@preview/wordometer:0.1.5": word-count-of #let fig = figure( rect[Figure content here], caption: [This is the caption text] ) // Count everything #word-count-of(fig) // Exclude entire figure (body and caption) #word-count-of(exclude: figure, fig) // Exclude only captions, count figure body #word-count-of(exclude: caption, fig) // Exclude figure body, count only captions #word-count-of(exclude: "figure-body", fig) ``` -------------------------------- ### word-count Source: https://context7.com/jollywatt/typst-wordometer/llms.txt The primary function for performing word counts. It can be used as a document show rule for global statistics or with a callback function for scoped counts. ```APIDOC ## word-count ### Description Performs word counting on document content. When used as a show rule, it tracks global statistics. When used with a callback, it provides scoped counts. ### Parameters #### Request Body - **callback** (function) - Optional - A function receiving a dictionary of counts (words, characters, sentences). - **exclude** (selector/array) - Optional - Elements to exclude from the count (e.g., headings, labels, or specific elements). - **counter** (function) - Optional - A custom function to define how text is counted. ``` -------------------------------- ### Excluding Elements from Word Count Source: https://github.com/jollywatt/typst-wordometer/blob/master/README.md Use the exclude parameter with selectors, functions, or labels to ignore specific document elements. ```typ #show: word-count.with(exclude: (heading.where(level: 1), strike)) = This Heading Doesn't Count == But I do! In this document #strike[(excluding me)], there are #total-words words all up. #word-count(total => [ You can exclude elements by label, too. #[That was #total.words, excluding this sentence!] ], exclude: ) ``` -------------------------------- ### Exclude elements from word counts Source: https://context7.com/jollywatt/typst-wordometer/llms.txt Filter out specific content like headings or labeled blocks using the exclude parameter with selectors or labels. ```typ #import "@preview/wordometer:0.1.5": word-count, total-words // Exclude level-1 headings and strikethrough text from count #show: word-count.with(exclude: (heading.where(level: 1), strike)) = This Heading Doesn't Count == But This One Does! In this document #strike[(excluding me)], there are #total-words words. // Exclude by label #word-count(total => [ One, two, three, four. #[That was #total.words words, not counting this sentence!] ], exclude: ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.