Problems with cross-reference and tikz figures

160 views
Skip to first unread message

Garrett Milam

unread,
Feb 24, 2021, 2:22:51 PM2/24/21
to PreTeXt support
Hey folks,
 I have run into some issues with processing my files with xsltproc and pdflatex in terms of cross-references not working. Try as I might, I can't track down the source nor find a solution. 

Here's my issue. I have a book project mt.xml which currently contains a few figures generated using tikz. The figures render fine when I process with xsltproc and pdflatex into a .pdf output file. So far, so good. But I have cross-referenced them in the text using <xref ref="foo"> in reference to the @xml:id attribute on the figure. (This has worked fine with lists and equations.)  However, pdflatex is throwing some errors (see below) and pretext also throws out some confusing PTX:ERRORs (also below).

I have attached the relevant portions of my .xml file and a screenshot of the .pdf output below. Not sure if it matters but I'm running bash on Windows 10 via WSL.

I am sure there is something simple I am missing. I am new to using @xml:id and @xref elements.

when running "xsltproc -o mt.tex /Documents/Micro_Text_Project/mathbook/xsl/pretext-latex.xsl src/mt.xml" in bash. (note: these errors/warnings appear multiple times)

PTX:ERROR:   An object (image) lacks a serial number, search output for "[NUM]"
             located within: "kumquat-demand-tikz" (xml:id)
PTX:ERROR:   An object (image) lacks a structure number, search output for "[STRUCT]"
             located within: "kumquat-demand-tikz" (xml:id)
MBX:WARNING: could not translate string with id "image" into language for code "en-US"

when running pdflatex:
LaTeX Warning: Hyper reference `x:figure:kumquat-demand-tikz' on page 5 undefin
ed on input line 538.

LaTeX Warning: Reference `x:figure:kumquat-demand-tikz' on page 5 undefined on
input line 538.
[5]

LaTeX Warning: Hyper reference `x:figure:kumquat-demand-tikz' on page 6 undefin
ed on input line 550.

LaTeX Warning: Reference `x:figure:kumquat-demand-tikz' on page 6 undefined on
input line 550.
[6]

Here is what is generated in the mt.tex file.
where xref occurs:
\hyperref[x:figure:kumquat-demand-tikz]{Figure~{\xreffont\ref{x:figure:kumquat-demand-tikz}}}

and where xml:id is used:

\begin{figureptx}{Kumquat Demand}{x:figure:kumquat-demand-tikz}{}%
\begin{image}{0.25}{0.5}{0.25}%
\resizebox{\linewidth}{!}{%
\begin{tikzpicture} scale=1


From mt.xml:
  <p>
    Now that we have introduced the idea of inverse demand, let's connect it to what you have likely seen before as a demand
    curve. <xref ref="kumquat-demand-tikz"/> below illustrates a simple linear inverse demand curve for kumquats. This shows us the quantity, price
    pairs representing demand for this fruit, taken all other variables impacting kumquat demand as given or constant. A change
    in one of these other variables leads to a change in the quantity demanded at each price, shifting the curve left or right.
     Looking at the impact on the demand curve of a change in a single
    non-price variable like this is called <em>comparative statics</em>.
  </p>
<p>
So let us consider what would happen [WORKING HERE]
</p>
  
    <figure xml:id="kumquat-demand-tikz">
    <caption>Kumquat Demand</caption>
    <image  width="50%">
        <description>A graph of kumquat demand.</description>
        <latex-image>

        \begin{tikzpicture} scale=1

          \draw[\lt-\gt,thick] (0,25) node (yaxis) [above] {$P$} |- (15,0) node (xaxis) [right] {$Q$};

          \draw (0,23) coordinate (b_1) -- (11.5, 0) coordinate (b_2);
          \coordinate(c) at (9,5);

         \draw[dashed] (yaxis |- c) node[left] {$5$}
                  -|  (xaxis -| c) node [below] {$9$};


          \fill [red] (c) circle (3 pt);
          \end{tikzpicture}

      </latex-image>
     </image>
     </figure>

Figure and missed reference section of .pdf:


Screenshot 2021-02-24 111421.png
Screenshot 2021-02-24 111509.png

Garrett Milam

unread,
Feb 24, 2021, 2:32:50 PM2/24/21
to PreTeXt support
Please disregard the above. I just did a new git pull of mathbook and tried again and everything works fine. I apparently had an issue with referencing an image earlier but once I switched the @xml:id over to the figure it worked fine.

Rob Beezer

unread,
Feb 24, 2021, 2:35:03 PM2/24/21
to pretext...@googlegroups.com
Dear Garrett,

Thanks for the complete report.

The three PTX(MBX) errors suggest PreTeXt is trying to form a cross-reference to
an "image" element, but can't find a string "Image" nor a number like 3.4.7.
Are you sure you do not have an "xref" *somewhere* with a @ref attribute that
points to an "image" (labeled with an @xml:id)?

Your four LaTeX errors suggests something going on with the Kumquat figure
*twice*, once on page 5 and again on page 6 (so in somewhat close proximity).
Look at lines 538 and 550 of your mt.tex file for clues as to location?

Reply if that does not lead to a quick resolution (and if it does!).

Rob
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/bee896eb-6f58-4b52-8c53-f9742b008cacn%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/bee896eb-6f58-4b52-8c53-f9742b008cacn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Rob Beezer

unread,
Feb 24, 2021, 2:35:38 PM2/24/21
to pretext...@googlegroups.com
OK! Ignore my troubleshooting. ;-)

Rob
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/cb7d7e4e-edbd-4a9e-bd1b-e07f5c3c123en%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/cb7d7e4e-edbd-4a9e-bd1b-e07f5c3c123en%40googlegroups.com?utm_medium=email&utm_source=footer>.

Garrett Milam

unread,
Feb 24, 2021, 2:49:00 PM2/24/21
to PreTeXt support
Ok. So there is something weird going on here. I changed my @xml:id attribute on two other figures from the image to the figure tag. However, when I processed with pdflatex a second time (just on a hunch since that was what generated the correct .pdf for the demand figure), the reference was there just fine.  Notably, I did not reprocess the mt.xml file between the two pdflatex runs.

Here is the output from pdflatex from each run that seems relevant. Note the undefined hyper reference warning in the first run that isn't there in the second. 

I can email or attach the .tex and dump output of pdflatex and/or xsltproc after replicating this situation if it would help.

1st run:
************************************************
Subsection 2.3.1 Supply Functions
************************************************
pdfTeX warning (ext4): destination with the same identifier (name{tcb@cnt@block
.1}) has been already used, duplicate ignored
<to be read again>
                   \relax
l.593 ...rminants of Supply}}{x:list:supply-det}{}
                                                  % [7]

LaTeX Warning: Hyper reference `x:figure:kumquat-supply-tikz' on page 8 undefin
ed on input line 624.


LaTeX Warning: Reference `x:figure:kumquat-supply-tikz' on page 8 undefined on
input line 624.

pdfTeX warning (ext4): destination with the same identifier (name{tcb@cnt@block
.2}) has been already used, duplicate ignored
<to be read again>
                   \relax
l.625 ...t Supply}{x:figure:kumquat-supply-tikz}{}
                                                  % [8] [9]

2nd run:
************************************************
Subsection 2.3.1 Supply Functions
************************************************
pdfTeX warning (ext4): destination with the same identifier (name{tcb@cnt@block
.1}) has been already used, duplicate ignored
<to be read again>
                   \relax
l.593 ...rminants of Supply}}{x:list:supply-det}{}
                                                  % [7]pdfTeX warning (ext4): d
estination with the same identifier (name{tcb@cnt@block.2}) has been already us
ed, duplicate ignored
<to be read again>
                   \relax
l.625 ...t Supply}{x:figure:kumquat-supply-tikz}{}
                                                  % [8] [9]

Garrett Milam

unread,
Feb 24, 2021, 3:23:06 PM2/24/21
to PreTeXt support
Also, FYI. The Author Guide example of using tikz (the RNA Codons figure) puts the @xml:id in the image tag. https://pretextbook.org/doc/guide/html/topic-images.html
This is what originally led me astray.

Rob Beezer

unread,
Feb 24, 2021, 3:24:30 PM2/24/21
to pretext...@googlegroups.com
I think this is normal. LaTeX requires two passes to resolve a cross-reference.
On the first pass it should produce a "??". (PreTeXt only requires one pass).

Once in the swing of things, you can just edit, do a LaTeX pass, edit, do
another LaTeX pass, etc. And your cross-referneces will eventually catch up.
There is some more-complicated layout that can sometimes take *three* LaTeX
passes. So be careful with a *production* run.

Holler if I mis-understood something.

Rob
> https://groups.google.com/d/msgid/pretext-support/45127be4-f0bd-4586-a237-d91ddc0ec4ddn%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/45127be4-f0bd-4586-a237-d91ddc0ec4ddn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Rob Beezer

unread,
Feb 24, 2021, 3:33:59 PM2/24/21
to pretext...@googlegroups.com
*That* xml:id is to provide words for a meaningful file name for the HTML
version of the image. Which was part of a poor design decision (very early
on!), which I am in the middle of walking back. (So an xml:id problem was
making me very nervous - there is some brand-new code nobody should notice if it
is correct.)

Reporting items like this that trip up people early on is *very* useful. So
please keep those observations coming. We've forgotten what it is like to be
new. ;-)

Rob
> https://groups.google.com/d/msgid/pretext-support/d5a5b5d8-ee8f-4889-a4ae-580ec61ec49en%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/d5a5b5d8-ee8f-4889-a4ae-580ec61ec49en%40googlegroups.com?utm_medium=email&utm_source=footer>.

Garrett Milam

unread,
Feb 24, 2021, 4:00:07 PM2/24/21
to PreTeXt support
I now recall that Latex takes two runs to resolve this. My rusty Latex skills are slowly returning and my grasp of XML/PreTeXt is slowly improving. 

FYI. Different issue but I ran into some trouble trying to build a table using latex-tables.com. 1. Even though I selected Pretext as output it placed a <caption> tag instead of a <title> (easily fixed), 2. it inserted some &nbsp (html issue?) and 3.  I also had some other syntax error when I processed with pdflatex. Here's the error it threw to the terminal: 

! Package inputenc Error: Unicode character ​ (U+200B)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.867 &if \(​
               \epsilon_{d} \lt -1\)&Elastic&\tabularnewline[0pt]



David Farmer

unread,
Feb 24, 2021, 4:07:44 PM2/24/21
to PreTeXt support

U+200B is a zero-width space, which should not have been there but
probably was copy-pasted.

Maybe you can delete that character by editing the file?
(the LaTeX error shows where it is).

What browser did you use to generate the table?

Can you paste into a message exactly what you copies from the
tables website?
> pretext-suppo...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/67ade274-6735-45ca-a64a-d4612ffa092fn%40googlegroups.com.
>
>

Rob Beezer

unread,
Feb 24, 2021, 4:18:19 PM2/24/21
to pretext...@googlegroups.com
On 2/24/21 1:00 PM, Garrett Milam wrote:
> My rusty Latex skills are slowly returning and my grasp of XML/PreTeXt is slowly improving.

Good and better. Eventually you (and everybody) else can let your LaTeX skills
rust into dust. ;-)

> FYI. Different issue but I ran into some trouble trying to build a table using
> latex-tables.com.

That's an independent project, but input like this is helpful, I can pass it along.

> 1. Even though I selected Pretext as output it placed a
> <caption> tag instead of a <title> (easily fixed), 2. it inserted some &nbsp
> (html issue?) and 3.  I also had some other syntax error when I processed with
> pdflatex. Here's the error it threw to the terminal:
>
> ! Package inputenc Error: Unicode character ​ (U+200B)
> (inputenc)                not set up for use with LaTeX.
>
> See the inputenc package documentation for explanation.
> Type  H <return>  for immediate help.
>  ...
>
> l.867 &if \(​
>                \epsilon_{d} \lt -1\)&Elastic&\tabularnewline[0pt]

As David, suggests it'll be good to know where that thin space came from.
Unicode characters behave better with the "xelatex" engine, rather than the
"pdflatex" engine. You've probably got it on your system, and it might be worth
giving it a try.

Rob

Garrett Milam

unread,
Feb 24, 2021, 5:16:09 PM2/24/21
to PreTeXt support
I used Chrome. 
Good to know Rob. I will use xelatex and see how that goes.
Here's what I copied from latex-tables.com (I removed the &nbsp content and switched caption to title.):
<table>
  <caption>
    Price Elasticity of Demand Categories
  </caption>
  <tabular>
    <row>
      <cell>
      </cell>
      <cell>
        Elasticity Value
      </cell>
      <cell>
        Demand at that Price is...
      </cell>
      <cell>
      </cell>
    </row>
    <row>
      <cell>
      </cell>
      <cell>
        if <m>​\epsilon_{d} \lt -1</m>
      </cell>
      <cell>
        Elastic
      </cell>
      <cell>
      </cell>
    </row>
    <row>
      <cell>
      </cell>
      <cell>
        if&nbsp;<m>​\epsilon_{d} = -1</m>
      </cell>
      <cell>
        Unit Elastic
      </cell>
      <cell>
      </cell>
    </row>
    <row>
      <cell>
      </cell>
      <cell>
        if&nbsp;<m>​\epsilon_{d} \gt -1</m>
      </cell>
      <cell>
        Inelastic
      </cell>
      <cell>
      </cell>
    </row>
    <row>
      <cell>
      </cell>
      <cell>
      </cell>
      <cell>
      </cell>
      <cell>
      </cell>
    </row>
  </tabular>
</table>

Sean Fitzpatrick

unread,
Feb 24, 2021, 5:42:19 PM2/24/21
to pretext...@googlegroups.com
I've found it helpful to double up the xml:ids, and do something like

<figure xml:id="fig-silly-cat-pic">
  <caption>...</caption>
  <image xml:id="img-silly-cat-pic">

The first id gets ref'ed and the second makes the file name.
PreTeXt will auto-generate numbered file names, but for me this causes
trouble.

When I'm publishing APEX, I've got a book with over 1000 images, and I
make three editions.
(Greg's official APEX, and two that are aligned to our course sequence
here.)

The main difference between the three editions is how the chapters and
sections are ordered.
If I don't have an xml:id on every image, I have to regenerate the
images for every HTML build. (If they come in a different order, they
get different names!)

David Farmer

unread,
Feb 24, 2021, 5:53:39 PM2/24/21
to PreTeXt support

It didn't really tell me what I want, because the email program
added a lot of extra formatting markup.

But this looks to me like the bad side of what Jeremy is trying to use
for good: he is having the permalink you copy automatically include
useful text, to save you typing. Often what you think you are copying
and pasting is not just the literal characters you see.

What I wanted (but failed) to find out, is whether it is the website or
your computer that is adding the & nbsp; and that nasty invisible space.

David


On Wed, 24 Feb 2021, Garrett Milam wrote:

> --
> You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> pretext-suppo...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/260ff21f-3861-4b13-98f7-4a78c32b7701n%40googlegroups.com.
>
>

Garrett Milam

unread,
Feb 24, 2021, 7:09:08 PM2/24/21
to PreTeXt support
I think the attached screenshots direct from the browser should help. One shows the window from which I copied the markup, the other shows what I entered in the input area. Looks to me like the website is creating the &nbsp (not sure about the U+200B).
Screenshot 2021-02-24 160530.png
Screenshot 2021-02-24 160557.png

Rob Beezer

unread,
Feb 24, 2021, 7:13:53 PM2/24/21
to pretext...@googlegroups.com
Thanks, Garrett. I'll likely file a report later with all of this.

On 2/24/21 4:09 PM, Garrett Milam wrote:
> I think the attached screenshots direct from the browser should help. One shows
> the window from which I copied the markup, the other shows what I entered in the
> input area. Looks to me like the website is creating the &nbsp (not sure about
> the U+200B).
>
> On Wednesday, February 24, 2021 at 2:53:39 PM UTC-8 far...@aimath.org wrote:
>
>
> It didn't really tell me what I want, because the email program
> added a lot of extra formatting markup.
>
> But this looks to me like the bad side of what Jeremy is trying to use
> for good: he is having the permalink you copy automatically include
> useful text, to save you typing. Often what you think you are copying
> and pasting is not just the literal characters you see.
>
> What I wanted (but failed) to find out, is whether it is the website or
> your computer that is adding the & nbsp; and that nasty invisible space.
>
> David
>
>
> On Wed, 24 Feb 2021, Garrett Milam wrote:
>
> > I used Chrome. Good to know Rob. I will use xelatex and see how that goes.
> > Here's what I copied from latex-tables.com <http://latex-tables.com> (I
> > > latex-tables.com <http://latex-tables.com>.
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/f8c5d5e8-a4ff-41eb-b1fb-6a0d818e349fn%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/f8c5d5e8-a4ff-41eb-b1fb-6a0d818e349fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

David Farmer

unread,
Feb 24, 2021, 8:52:43 PM2/24/21
to PreTeXt support

That looks like a bug on their website, which hopefully they can fix.
> https://groups.google.com/d/msgid/pretext-support/f8c5d5e8-a4ff-41eb-b1fb-6a0d818e349fn%40googlegroups.com.
>
>

Rob Beezer

unread,
Feb 25, 2021, 10:50:46 PM2/25/21
to pretext...@googlegroups.com
Titles, (new) header rows, non-breaking spaces, and thin spaces all reported
upstream on two issues. PTX issue to track both:

https://github.com/rbeezer/mathbook/issues/1451

Thanks again, Garrett!
Reply all
Reply to author
Forward
0 new messages