How to code circles around text in Mathjax - mathjax

The following image is from an exercise in Chiswell and Hodges Mathematical Logic, page 21:
I would like to display something similar when I post an answer on Mathematics Stack Exchange, but I don't know how to make the circles with the numbers inside nor the forward slashes through the letters in Mathjax. I think I can handle the fractions with "\frac" as well as the rest of it.
I've looked for examples from other posts to copy, but people seem to replace the circle with parenthesis as an alternative.
Would someone be able to show me how or what software I should use to get this effect?

There are a number of possible ways to get a circle around the one. Here are three:
Use the enclose extension with the circle notation:
\require{enclose}
{\scriptstyle \enclose{circle}{\kern .06em 1\kern .06em}}
You only need to include the \require{enclose} once on the page before your first usage of \enclose. The \kern commands are to make the circle be round rather than oval, since the size of the one is taller than it is wide.
Use \rlap to place the 1 over top of a \bigcirc:
{scriptstyle \rlap{\kern .18em 1}\raise.04em{\bigcirc}}}
we also raise the big circle slightly to get the placement better.
Use the \unicode{} command to obtain the U+2460 character, which is "circled digit one":
{\textstyle\unicode{x2460}}
You can use the cancel package to get \cancel, which produces an diagonal upward slash over its argument, and use a superscript to put the circled 1 in place:
{scriptstyle\cancel{\psi}^{\raise.2em{\enclose{circle}{\kern .06em 1\kern .06em}}}}
Putting this all together with your fractions, you can do something like the following horrible hack:
\require{enclose}\require{cancel}
\frac{
\lower.3em{\scriptstyle\cancel{\psi}\raise.6em{\enclose{circle}{\kern .06em 1\kern .06em}}}
\kern 2.6em
\frac{(\psi\wedge\phi)}{\phi}
{\scriptstyle (\wedge\rm E)}
\kern -2.5em
}{
\kern -.7em
{\scriptstyle\enclose{circle}{\kern .06em 1\kern .06em}}
\frac{(\psi\wedge\phi)}{(\psi\rightarrow(\psi\wedge\phi))}
{\scriptstyle(\rightarrow\rm I)}
\kern -1.7em
}\ {\scriptstyle (\wedge\rm I).}
This includes a lot of spacing adjustments by hand to get the fraction lines to be the right length. It would be painful to do this for very many of these.
Here is the result:

Related

Add double lines in the middle of another svg line

so I have a drawing program and I need to implement a "broken line", it is an SVG line with two another lines in the middle of this line, these two line needs to cross perpendicularly to the principal line, maybe this picture can help me to explain the problem:
This line can be drawn in any angle that the user choose
I don't really understand svg's so I'm having a lot of trouble implementing this.
Thank you
So I discovered one way to implement that using polylines and calculating the middle of the source and target coordinates, so when it changes I change the middle point too. After that, I created a marker-mid with the double lines.

Partial ligature selection with DirectWrite

Using HitTestTextPosition style API from IDWriteTextLayout I did not managed to handle properly text positions inside "ti", "ffi" or other ligatures with fonts like Calibri. It always returns position after or before ligature not inside like t|i or f|f|i.
What is the recommended way to do a caret movement inside ligatures with DirectWrite API?
There... is no "inside" position if you have GSUB replacements turned on?
Opentype GSUB ligatures are single glyph replacements for codepoint sequences, rather than being "several glyphs, smushed together". They are literally distinct, single glyphs, with single bounding boxes, and a single left and right side bearing for cursor placement/alignment. If you have the text A + E and the font has a ligature replacement that turns it into Ӕ then with ligatures enabled there really are only two cursor positions in that code sequence: |Ӕ and Ӕ|. You can't place the cursor "in the middle", because there is no "middle"; it's a single, atomic, indivisible element.
The same goes for f. ligatures like ff, fi, fl, ffi, ffl, or ſt: these are single glyphs once shaped with GSUB turned on. This is in fact what's supposed to happen: having GSUB ligatures enabled means you expressly want text to be presented—for all intents and purposes—as having atomic glyphs for many-to-one substitutions, like turning the full phrase "صلى الله عليه وعلى آله وسلم‎", as well as variations of that, into the single glyph ﷺ.
If you want to work with the base codepoint sequences (so that if you have a text with f + f + i it doesn't turn that into ffi) you will need to load the font with the liga OpenType feature disabled.
The text editors I know of use the simple hack of (1) dividing the width of the glyph cluster by the number of code points within the cluster (excluding any zero width combining marks), rather than use the GDEF caret positioning information. This includes even Word, which you can tell if you look closely enough below. It's not precise, but since it's simple and close enough at ordinary reading sizes, it's what many do:
(2) I've heard that some may (but don't know which) also use the original glyph advances of the unshaped characters (pre-ligation) and scale them proportionally to the ligature cluster width.
(3) Some text editors may use the GDEF table, but I never knew of any for sure (possibly Adobe In-Design?).
The most challenging aspect of using methods 2 or 3 with IDWriteTextLayout is that accessing the corresponding IDWriteFontFace in that run requires quite the indirection because the specific IDWriteFontFace used (after resolving font family name+WWS+variable font axes) is stored in the layout but not publicly accessible via any "getter" API. The only way you can extract them is by "drawing" the glyph runs via IDWriteTextLayout::Draw into a user-defined IDWriteTextRenderer interface to record all the DWRITE_GLYPH_RUN::fontFace's. Then you could call IDWriteFontFace::GetDesignGlyphAdvances on the code points or IDWriteFontFace::TryGetFontTable to read the OpenType GDEF table (which is complex to read). It's a lot of work, and that's because...
The official PadWrite example has the same issue
IDWriteTextLayout was designed for displaying text rather than editing it. It has some functionality for hit-testing which is useful if you want to display an underlined link in a paragraph and test for it being clicked (in which case the ligature would be whole anyway within a word), or if you want to draw some decorations around some text, but it wasn't really intended for the full editing experience, which includes caret navigation. It was always intended that actual text editing engines (e.g. those used in Word, PowerPoint, OpenOffice, ...) would call the lower level API's, which they do.
The PadWrite sample I wrote is a little misleading because although it supports basic editing, that was just so you can play around with the formatting and see how things worked. It had a long way to go before it could really be an interactive editor. For one (the big one), it completely recreated the IDWriteTextLayout each edit, which is why the sample only presented a few paragraphs of text, because a full editor with several pages of text would want to incrementally update the text. I don't work on that team anymore, but I've thought of creating a DWrite helper library on GitHub to fill in some hindsight gaps, and if I ever did, I'd probably just ... use method 1 :b.

Should I use d3.js to draw lines between paragraphs of text?

I intend to create a system with two columns of text. There will be lines that indicate connections between some paragraphs on the left with some paragraphs on the right that appear when you mouseover them. Should I be using d3.js or is that overkill for this purpose?
EDIT: to be clear, some of the paragraphs on the left may not be aligned with the ones on the right so there would be crossing diagonal lines all along the middle.
Krzysztof is correct in that you might want to consider more complex interactions in the future. If you really just need a line, though, then D3.js is definitely overkill. Several commenters have suggested CSS borders, but I don't know if that approach meets your needs. If you want to draw straight lines between paragraphs, those lines won't, presumably, always be strictly horizontal or vertical. A more flexible option would be to add an absolutely positioned <div> into the page, hiding or showing it as appropriate. The <div> can have a 1px height and a background color to simulate a line, and it can be transformed using translation and rotation to connect any two arbitrary points.
No, use CSS instead. If you provide HTML code then we can guide you with CSS. Check out CSS borders: http://www.w3schools.com/css/css_border.asp
it depends on many factors. If you need d3.js only for 'draw lines/arrows' then I think this is overkill (d3.js is bigger then jquery). This looks like some simple task with basic tools. But if this is data presentation, which in future may be more complex, and when you use d3 for other charts, it will be fine.
Edit: because OP edit:
Look at this in semantic way. If this is data presentation then yes, If this is graphic effect then no.
No. D3 = "Data-Driven Documents". D3 uses SVG, and adding an SVG into your page just to draw a line is an absolute overkill. As a rule, you should take the simplest approach, hence a CSS border should do the job
border-bottom: 2px solid red;
for example.

Detect collision between svg path and svg text

Suppose I have a svg path and a piece of text. I want to figure out where they intersect. I'm not really sure where to start, because the svg path's getBBox() function does not help.
Where should I start?
You have the text bounding box via getBBox(). Unfortunately, as you may have already discovered, that is not a tight bounding box of the glyphs. It includes the full descender and ascender heights of the font. However it should get you a reasonable approximation.
The next step is to determine where the path hits the bounding box. Getting a perfect mathematical solution is very hard, but there are iterative approaches that are much easier and give good results.
Path elements have a couple of DOM functions that can help: getTotalLength() and getPointAtLength(). You can step along the path from 0 to the path length, calling getPointAtLength(), until the point returned is inside the text bbox.
If you want to get more accurate and determine which character in the text touches the line, there are some DOM functions on SVG text elements that should be useful. For instance, `getExtentOfChar(n) returns the bounds of the nth character in the text.

LaTeX \includegraphics and textline

Ok, I am beat. I tried a few things but I am unable to make this happen. I need some help now.
I want to be able to have some text and picture side by side (only one line, thus no need for wrapping or other fun. The picture is small enough to fit in a text line):
This is a text <temp.jpg placed center to the textline>
Problem is, when I use
This is a text \includegraphics{temp.jpg}
the pictures baseline is alligned with the text baseline. I want the picture (vertical) center to be aligned with the text baseline. How can I make this possible?
This is a text $\vcenter{\hbox{\includegraphics{temp.jpg}}}$
It sounds like you want \raisebox (see the raisebox section of the LaTeX wikibook), with a negative argument. Use dimensions ex (the notional height of an 'x' in the current font) or \baselineskip (the size between text baselines) as your units.
If you want to do more complicated things, such as move the graphics box down by half its height, you can, but it gets fiddly. If the graphic size isn't unpredictable, you're probably better off tuning this by hand anyway.
In my opinion, most simple answer \raisebox{-0.5\totalheight}{<your graphic here>}
This is a text \raisebox{-0.5\totalheight}{\includegraphics{temp.jpg}}
Explanation:
\raisebox moves vertically the whole text/picture given as second argument. The first argument is the vertical shift as a length. This command provides the length \totalheight which is, self-explanatory, the height of the whole text/picture that you want to raise. The factor -0.5 lowers exactly at the half of the length(as the question demands). For aesthetic adjustments just modify the factor's value.
By the way, with this method there is no need to get into math mode as in #AlexeiMalistov answer, and no need of double command \vcenter + \hbox

Resources