4

Can someone explain to me this command right above the document command step by step:

\documentclass{article}

\usepackage{amssymb,amsmath}
\usepackage{xypic}
\usepackage[czech]{babel}
\newcommand{\pullbackcorner}[1][dl]{\save*!/#1-1pc/#1:(1,-1)@^{|-}\restore}

\begin{document}
      $$
  \xymatrix@=3pc{
    & & D \\
    B \ar[r]\ar@/^/[rru]^{h} & P \ar[ru] \pullbackcorner & \\
    A \ar [u]^f \ar[r]_g & C \ar[u]\ar@/_/[ruu]_{k} &
  }
  $$
\end{document}

It works as it should but I do not follow HOW.

  • 1
    Welcome to TeX.se. Please don't post code fragments. Instead put the fragment into a compilable minimal document so that people can see exactly what you're doing. You can format code selecting it and clicking on the {} icon. (Unrelated, but you shouldn't use $$ ... $$ in LaTeX). – Alan Munn Jun 2 at 14:31
  • Why should not I use $$....$$ in LaTeX? It works fine. – user2925716 Jun 2 at 14:41
  • Sorry for my confusions, my Q. is now as is intended to be. – user2925716 Jun 2 at 14:43
  • @user2925716 See this link of the very good user Sigur: tex.stackexchange.com/questions/362760/… – Sebastiano Jun 2 at 14:44
  • 1
    On use of $$ see Why is [ … ] preferable to $$ … $$? – Alan Munn Jun 2 at 14:48
8

There's quite a bit to unpack in this command, but much of it is just regular XY syntax, which is quite tough to follow unless you use it a lot (which I don't).

Perhaps the part you don't understand is the \save ... \restore part, which is really crucial to understanding how the command works the way it does. So I'll start with a very simple example and we'll build things up piece by piece.

As a historical note, the original source of the macro itself seems to be lost, but there's an early reference to it (acknowledging an unknown source) in the archives of the XY mailing list: https://tug.org/pipermail/xy-pic/2001-July/000015.html.

The * operator

The basic part of the command uses the * operator to place arbitrary text. To see how this works, let's use * to place a red X in the diagram:

\[
  \xymatrix@=3pc{
    & & D \\
    B \ar[r]\ar@/^/[rru]^{h} & P \ar[ru] *{\color{red} X} & \\
    A \ar [u]^f \ar[r]_g & C \ar[u]\ar@/_/[ruu]_{k} &
  }
\]

output of fragment

Since this * code is at the end of an \ar command, it places the text at the end of the arrow, which ends up right on top of the D. Since this is for illustrative purposes, we don't care about that.

\save and \restore

Now let's do the same thing, but instead wrap the * code in {\save ... \restore}:

\[
  \xymatrix@=3pc{
    & & D \\
    B \ar[r]\ar@/^/[rru]^{h} & P \ar[ru] \save*{\color{red} X}\restore & \\
    A \ar [u]^f \ar[r]_g & C \ar[u]\ar@/_/[ruu]_{k} &
  }
\]

Now the X is right on top of the P. This is what \save and \restore do. They allow objects to be added relative to the current position. In this case the current position is P not the end point of the arrow.

output of fragment

Positioning parameters

So this is the basics of what the \pullbackcorner command does. It places a arbitrary text (in this case the corner symbol) relative to the current position rather than at the end of the path. So we can now unpack the rest of the command:

\newcommand{\pullbackcorner}[1][dl]{\save*!/#1-1pc/#1:(1,-1)@^{|-}\restore}

The \pullbackcorner is a macro that takes one optional argument (a direction specification) whose default is dl. This is the \newcommand{\pullbackcorner}[1][dl] part of the macro.

It then places the corner symbol @^{|-} (which is really not a symbol, but one of the many xy-pic arrowheads) 1pc away from from the current position in the dl direction /#1-1pc/ (where #1 will be dl by default), with an orientation set by the Cartesian coordinates #1:(1,-1), i.e., relative to #1 (by default dl) set the origin to (1,-1). Changing the 1pc value will move the corner closer or further away from the current position, and changing the (1,-1) values will change the orientation of the corner itself.

Here are a couple of more examples changing those values:

We can move the corner further away:

\renewcommand{\pullbackcorner}[1][dl]{\save*!/#1-3pc/#1:(1,-1)@^{|-}\restore}

\[
  \xymatrix@=3pc{
    & & D \\
    B \ar[r]\ar@/^/[rru]^{h} & P \ar[ru] \pullbackcorner & \\
    A \ar [u]^f \ar[r]_g & C \ar[u]\ar@/_/[ruu]_{k} &
  }
\]

output of fragment

We can rotate the corner:

\renewcommand{\pullbackcorner}[1][dl]{\save*!/#1-1pc/#1:(-1,1)@^{|-}\restore}

\[
  \xymatrix@=3pc{
    & & D \\
    B \ar[r]\ar@/^/[rru]^{h} & P \ar[ru] \pullbackcorner & \\
    A \ar [u]^f \ar[r]_g & C \ar[u]\ar@/_/[ruu]_{k} &
  }
\]

output of fragment

We can supply an optional argument to the macro to change the relative positioning of the corner (in this example, ul).

\[
  \xymatrix@=3pc{
    & & D \\
    B \ar[r]\ar@/^/[rru]^{h} & P \ar[ru] \pullbackcorner[ul] & \\
    A \ar [u]^f \ar[r]_g & C \ar[u]\ar@/_/[ruu]_{k} &
  }
\]

output of fragment

  • What a nice explanation! May I ask you yet in which context does $|-$ typeset that pushout sign? When I tried $$|-$$ it typesets completely other symbol. – user2925716 Jun 2 at 18:26
  • This works: $$ \xymatrix@=10pc{ \pullbackcorner } $$ CAN I REMOVE this: \xymatrix@=10pc{ } ? – user2925716 Jun 2 at 18:38
  • @user2925716 This is XY syntax, not a TeX symbol. It's basically an arrow tip. See section 2.3 of the XY guide. – Alan Munn Jun 2 at 18:39
  • OK. What does the parameter =10pc do? – user2925716 Jun 2 at 18:40
  • I'm not really sure what you're asking. The @=10pc sets the row and column spacing for the matrix. You shouldn't use the XY code just to get the symbol in other contexts. For that use one of the various \..corner symbols (e.g. amsmath \ulcorner etc.) And please stop using $$ :) – Alan Munn Jun 2 at 18:44

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.