but this does not work.
The following does seem to work:
$ lr(dif / (dif x) x^2 |)_3 &= 6 $
but I am not sure if the spacing is correct and am uneasy about the document semantics now reflecting the subscript attaching to the expression as a whole, not the right delimiter.
Additionally, the above would not work if the expression had an unclosed left parenthesis, e.g.:
$ lr(\( sum^* |) $
will always size the parenthesis and the bar together, which is not necessarily desirable.
If there is no reliable way to do this currently, might I suggest the following change:
Make lr take optional named arguments left and right, which can be content, none, or auto. The default is auto, in which case the delimiter is inferred from the text. Otherwise the provided content is affixed and sized appropriately, unless none is used. Since math mode would not interpret none as a literal, perhaps a string can be passed instead, which is either interpreted as a delimiter, e.g. "(", "|", or "none", or "auto". Perhaps, in analogy to mat, a delim parameter could be provided, too, which would take either the left delimiter with an implicit mirrored right delimiter, or a tuple.
This is indeed the correct way to do it. As for the document semantics, it is obviously more complex to read than without lr, but it is only used here to specify that | must scale with the rest of the previous content.
About the subscript, it is not only semantics, but it is actually attached to lr.