A \webtext marks a named piece of running text that the page can replace: a counter, a clock, a value computed by a script. TEX typesets the default text, which is what the PDF shows. On the web a script sets new text, and the paragraph re-breaks around it.
apples
The basket holds no apples at all. The count comes from the page’s script: press the buttons above, and the lines around it re-break to make room for the new words.
The basket holds \webtext{apples}{no apples at all}. The count comes
from the page's script: press the buttons above, and the lines around it
re-break to make room for the new words.
The page’s own script:
constwords=['no apples at all','a single apple','two apples','three apples',/* … */];letn=0;functionshow(){field.value=n;reflowtex.host.setText('apples',n===0?null:words[n]??`${n} apples`);// null: TeX's own default
}stepper.addEventListener('click',e=>{n=Math.max(0,n+Number(e.target.dataset.step||0));show();});field.addEventListener('input',()=>{n=Math.max(0,parseInt(field.value,10)||0);show();});
How it is set
TEX sets the default as it sets any text. A text the page gives instead is set the way a browser sets it: in the default’s font and colour, word by word, each word measured by the browser, with no kerning or ligatures from one word to the next. It breaks only at its spaces, and between its words stands the interword glue of that font, with the stretch and shrink TEX would give it, so the line it lands on is justified with the rest. A no-break space (U+00A0) is a tie, as in TEX: the same glue, never broken.
reflowtex.host.setText(name, text) shows text in every \webtext of that name, in every block of the page; several changes within one frame are laid out together, and only the lines around them are drawn again. null brings back TEX’s default.
instance.setText(text) the same for one \webtext: each is an instance of kind text, found with reflowtex.host.instances({kind: 'text', name: 'apples'}). Its own text wins over its name’s.
A \webtext belongs in running text: inside a box, such as \mbox, its default cannot be replaced. In print it is its default, typeset as usual.
To insert HTML instead of words, such as a badge or a small control, see the next page, HTML widgets.