Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sum of my PGF, SVG, XY patches #2505

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

xworld21
Copy link
Contributor

@xworld21 xworld21 commented Feb 2, 2025

This includes #2502 (better horizontal alignment, mostly for XY), #2488 (better overall alignment of foreignObject, with TikZ matrix improvements), #2477 (PGF baseline), #2401 #2490 (respect PGF bounding boxes), #2397 #2396 (add SVG viewBox in both PGF and XY).

I didn't add \pgfmathparse because, ahem, it fails badly.

Edit: the document I have been using as reference

\documentclass{article}
\usepackage[all,cmtip]{xypic}
\usepackage{tikz}
\usetikzlibrary{cd}
\newcommand\tikzname{Ti\emph{k}Z}
\begin{document}

\xymatrix{A \ar[d]^q \\ B }

\noindent Inline \Xy-matrix: $\xymatrix{
  A \ar[rd] \ar^\phi[r] & B \\
                        & C }$.

\xymatrix{
A \ar@{->>}[rd] \ar@{^{(}->}[r]
&B \ar@{.>}[d]
&C \ar@{_{(}->}[l]\ar@{->>}[ld]\\
&D}

\[
\xymatrix{
T \ar@/_/[ddr]_y \ar@/^/[drr]^x \ar@{.>}[dr]|-{(x,y)}\\
&X \times_Z Y \ar[d]^q \ar[r]_p & X\ar[d]_f \\
&Y \ar[r]^g &Z}
\]

\noindent Inline \tikzname-picture: \begin{tikzpicture}
  \draw (0.5,0.5) node {$2$};
  \draw (1.5,0.5) node {$+$};
  \draw (3,0.5) node {$3$};
  \draw (4.5,0.5) node {$=$};
  \draw (7,0.5) node {$5$};
  \draw (0,0) node [below] {$0$} -- (1,0) node [below] {$1$};
  \draw (1.5,0) node {$+$};
  \draw (2,0) node [below] {$0$} -- (3,0) node [below] {$1$} -- (4,0) node [below] {$2$};
  \draw (4.5,0) node {$=$};
  \draw (5,0) node [below] {$0$} -- (6,0) node [below] {$1$};
  \draw [dashed] (6,0) -- (7,0);
  \draw (7,0) node [below] {$2$} -- (8,0) node [below] {$3$} -- (9,0) node [below] {$4$};
  \foreach \x in {0,1,2,3,4,5,6,7,8,9} {
      \fill (\x,0) circle (0.05);
    }
\end{tikzpicture}

\noindent Inline \tikzname-cd: \begin{tikzcd}
A \arrow[r, "\phi"] \arrow[d, red]
& B \arrow[d, "\psi" red] \\
C \arrow[r, red, "\eta" blue]
& |[blue, rotate=-15]| D
\end{tikzcd}

\noindent Another one: \begin{tikzcd}
  A \arrow[r, "\phi\eta" near start, "\psi"', "\eta" near end] & {\hbox{\large B}}
\end{tikzcd}

\end{document}

@brucemiller
Copy link
Owner

Wow! Thanks! ! This is really very helpful to collect the (somewhat scary) batch of patches together to try out. I applied it to my collection of tikz & xy tests with interesting results! It's really gratifying that you were able to recover the viewport, without reintroducing the bad text positioning which was what drove me to disable it. In fact, in most cases, the text positioning is much improved! I wonder if this eventually could lead to clearing up the point vs pixel schizo that I introduced for the same (or similar) reason? (seems we should be able to generate XML with a single consistent unit; possibly rem?)
FWIW: There're 2 situations where this patch is slightly worse than the current: Math nodes are often positioned very slightly high; and when multiple lines of text are present, the interline spacing is too small (whereas the current code is too large?). In general, it's definitely a net improvement. I'll want to study your patches, though...

@xworld21
Copy link
Contributor Author

xworld21 commented Feb 5, 2025

seems we should be able to generate XML with a single consistent unit; possibly rem?

rem would be great, especially if paired with adjusting NOMINAL_SIZE based on 10/11/12pt.

when multiple lines of text are present, the interline spacing is too small

Vertical alignment is still not quite perfect. There are two issues that I can formulate clearly:

  • foreignObject should sometimes ignore the depth (e.g. for TikZ nodes, which are anchored at their geometric centre). For now I opted for keeping the baselines in check, because that seems less unpleasant. I don't know if the 'right' way is to make foreignObject react on context (but how?), or whether depth alignment should be done by the context (e.g. patching \hbox in PGF).
  • multiline text clashes with line-height:$height badly, and yet that's the only way to position stuff by baseline in CSS. When this is coming from \hbox, I suggest disabling word wrapping (actually \hbox should always disable word wrapping, but I digress). For vertical boxes, I haven't thought about it! Resetting to line-height:normal or line-height:$baselineskip would certainly mitigate the issue.

Then there's still something off with Alignment and depths and XY which I just don't get at the moment, and I am sure tons of other situations I haven't considered...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants