0

As I understand it, when TeX reads a glyph TeX puts the glyph into a character box. It pays attention the left sidebar and right sidebar, so negative sidebars are handled correctly (as are positive sidebars). The character box also has a baseline, which is picked up from the font and a depth and height which is picked up from the individual glyph.

How do I explicitly set the depth and height for a specific glyph? Here is a sample program that displays two similar glyphs with their surrounding box displayed. I want to set the depth and height of the box for a specific character or equivalently, enclose them in a box with specified width, depth and height allowing the ink to overflow.

\documentclass[10pt]{article}

\usepackage{unicode-math}

\setmainfont{STIX Two Text}[NFSSFamily=mainfont]
\setmathfont{STIX Two Math}[NFSSFamily=mathfont]

\usepackage{logix}

\usepackage[svgnames]{xcolor}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.05pt}

\begin{document}

   \fbox{\color{green}\KntTSLABSLA}  \fbox{\color{green}\KntLSUARSUA}

   \end{document}

And here is the output (blown up 16x for clarity).

The containing box for the symbol on the left should be going down the middle of the arrows in the same manner as the symbol on the right. The containing box for the symbol on the right is too low on the bottom and too high on the top, it should be like the symbol on the left for the ends of the arrows.

This problem is not specific to a particular font. I used the glyphs which were convenient for illustration. Here is an example not using that font.

\documentclass[10pt]{article}

\usepackage{unicode-math}

\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}

\usepackage[svgnames]{xcolor}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.05pt}

\begin{document}

   \fbox{\color{green}A}  \fbox{\color{green}J}

   \end{document}

and its output is

enter image description here

For this example, the height should be set to the middle of the cross bar in the "A" and the depth to the top of the hook in the "J". This is exactly the same problem, just different glyphs.

  • I don't know about logix.sty, nor does CTAN. No idea about \KntTSLABSLA and \KntLSUARSUA – egreg Jun 14 at 17:24
  • I should have mentioned. The logix package is under development. I am writing the package documentation now, and hopefully it will be up in a week or so. But, you can pick any character from any font to set the depth and height. – Michael Lee Finney Jun 14 at 17:57
  • e-TeX has primitives to retrieve said dimensions (\fontcharht and \fontchardp), but in order to set them, I believe you would have to modify the font files ( .tfm for non-UTF-8 engines). You can always create macros that output glyphs and pretend they have different height and depth using \raisebox, but I doubt this is what you are looking for. – frougon Jun 14 at 18:42
  • I have found that the \adjustbox command in the adjustbox package can do it, but I haven't figured out how yet. Bound to be some TeX primitive. I am still experimenting with that, but it at least shows that it is possible. I don't want to use the adjustbox package, however, since it seems to have some conflicts with the xcolor package I use a lot. – Michael Lee Finney Jun 14 at 19:03
  • Sorry, but this seems quite specific to the described glyphs, so without them it's very difficult to give advice. – egreg Jun 14 at 19:38
2

Character nodes share some properties with boxes but they are not boxes in the TeX model and their dimensions are not assignable.

You give no information about the system you are using but judging by your examples it is presumably xetex or luatex.

in classic tex or xtex you would have to make a new font external to tex with different metrics. With luatex you would in principle be able to use its virtual font features to programmatically construct a virtual font, however even with luatex, the system has no information about the shape of the glyph within its bounding box, so if you want to trim to the top of the tail of a J you need to clip it "by eye" or open up the font in a font editor and determine its constituent paths.

  • David, thanks for looking at this. I know the dimensions -- it is my font. The collectbox package was written by Martin Scharrer, and claims to be compatible with all versions of LaTeX (DVI-LaTeX, pdfLaTeX, XeLaTex and LuaLaTex) and does not rely on any other packages. Making another font would not solve the problem, the symbols have their dimensions by design. The sidebearings are picked up and so there is no problem horizontally. It is vertical matching. LaTeX picks up the actual top and bottom of the bounding box, so I have to change that. So far no problem with the solution I posted. – Michael Lee Finney Jun 14 at 23:09
  • 1
    @MichaelLeeFinney sorry I do not understand your comment at all. The collectbox usage in your answer doesn't seem that related to the question, it is certainly not doing what is asked which is altering the glyph metrics. – David Carlisle Jun 14 at 23:29
  • David, but it is. It has altered the bounding box that TeX uses to typeset the line. This allows me to have a string of symbols which have varying depth and height metrics, and to reliably put them in a string and all be treated identically with the same depth and height metrics. It does not alter the font itself of course. The change is seen in the fbox frame in my answer compared to my question. That frame represents the metrics used for the bounding box. The horizontal was always correct since it is taken from the font. But there is no equivalent for vertical metrics. – Michael Lee Finney Jun 15 at 0:11
  • 1
    @MichaelLeeFinney no your question asks how to set the height and depth for a glyph, and my answer points out that (aside from luatex) glyph metrics are read only. Your answer does something entirely different, it sets a box with externally assigned height and depth, that is of course possible in tex. Now in your example the box may have content just a single character but that is not really that relevant to the construction. So your answer may be what you need which is fine, but it doesn't answer the question that you actually asked (also no one can run the example code without the font) – David Carlisle Jun 15 at 0:16
  • David, I may have not been clear about what I was asking -- but this is exactly what I wanted. I wanted to take a glyph from my font and put in a box lying to TeX about its actual depth and height -- but allowing the ink to spill over. I thought that I was clear, but for practical purposes I'm not sure there is a difference between what I said and what I want. As far as the font is concerned, I am working hard to get ready to put it on CTAN. I am working on the documentation and trying to clear up a couple final points that I want handled first. – Michael Lee Finney Jun 15 at 0:40
0

I have found a solution using the collectbox package. This is a fairly small package, which is used by the much more complex adjustbox package (and written by the same author). Here is the solution.

\documentclass[10pt]{article}

\usepackage{unicode-math}

\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}

\usepackage{logix}
\usepackage{collectbox}

\usepackage[svgnames]{xcolor}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.01pt}

\newcommand  \fixdim[1] {\collectbox*{\setlength{\depth}{0.238em}\setlength{\height}{0.762em}}{#1}}

\begin{document}

   \fbox{\color{green}\fixdim{\KntTSLABSLA}}  \fbox{\color{green}\fixdim{\KntLSUARSUA}}

   \end{document}

and here is the resulting output

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.