jupyter-book icon indicating copy to clipboard operation
jupyter-book copied to clipboard

Reference an admonition?

Open nathanael-fijalkow opened this issue 5 years ago • 12 comments

It seems that admonitions cannot be referenced to? I'm using them as theorems for a maths book, so it'd be very useful to refer to them directly.

Many thanks for this great project!

nathanael-fijalkow avatar Feb 04 '21 14:02 nathanael-fijalkow

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Feb 04 '21 14:02 welcome[bot]

Hey @nathanael-fijalkow I believe you can, using the name option. Have you tried

```{admonition} My Title
:name: my-reference

content
```

chrisjsewell avatar Feb 04 '21 23:02 chrisjsewell

Thanks @chrisjsewell for the reply!

Am I doing something wrong? In the following file:

```{note}
:name: my-reference

content
```

Here is [](my-reference)

I get: WARNING: label 'my-reference' not found. WARNING: 'myst' reference target not found: my-reference

nathanael-fijalkow avatar Feb 05 '21 10:02 nathanael-fijalkow

Let me add a second test, that may explain some things. It's from the documentation:

```{table} My table title
:name: my-table-ref

| header 1 | header 2 |
|---|---|
| 3 | 4 |
```

Here is {ref}`my-table-ref`

Here is {ref}`My cool table <my-table-ref>`

Here is [](my-table-ref)

Here is [My cool table](my-table-ref)

Here is {numref}`my-table-ref`

Here is {numref}`Custom Table my-table-ref text`

I get a correct HTML output, however: WARNING: label 'my-table-ref' not found. WARNING: label 'my-table-ref' not found. WARNING: undefined label: custom table my-table-ref text (this last warning matches the last line)

Many thanks for your help!

nathanael-fijalkow avatar Feb 05 '21 11:02 nathanael-fijalkow

I think this would work:

```{note}
:name: my-reference

content
```

Here is {ref}`my reference<my-reference>`

Edit: sorry cross-posting.

NatalieZelenka avatar Feb 05 '21 11:02 NatalieZelenka

Many thanks @NatalieThurlby , it works!

Maybe this part of the documentation needs some fixing then?

Thanks again to both @chrisjsewell and @NatalieThurlby

nathanael-fijalkow avatar Feb 05 '21 12:02 nathanael-fijalkow

Wait I'm going to re-open this for now; are you saying essentially that {ref}`a-ref` works, but [](a-ref) does not? This should not be the case.

Given that you are using numref, I assume that you have numfig=True set? Have you tried without this being set?

chrisjsewell avatar Feb 05 '21 12:02 chrisjsewell

Sorry for closing that issue too early.

Forgetting about numref for now (where do you put it? In _config.py, as numfig:true?), here are the results of my experiments:

Here is {ref}`my reference<my-table-ref>`

Here is [My cool table](my-table-ref)

Here is {ref}`my-table-ref`

The first works fine.

The second works, but I get the following warning: WARNING: label 'my-table-ref' not found.

The third one does not work, and I get the following warning: WARNING: Failed to create a cross reference. A title or caption not found: my-table-ref

nathanael-fijalkow avatar Feb 05 '21 12:02 nathanael-fijalkow

No problem thanks,

Could you copy or attach the exact terminal/logging output here please

chrisjsewell avatar Feb 05 '21 15:02 chrisjsewell

Here you go @chrisjsewell

This is simple.md

# Simple

```{note}
:name: my-table-ref

content
```

Here is {ref}`my reference<my-table-ref>`

Here is [My cool table](my-table-ref)

Here is {ref}`my-table-ref`

This is the output to jb build test

Running Jupyter-Book v0.10.0 Source Folder: ./test Config Path: ./test/_config.yml Output Path: ./test/_build/html Running Sphinx v3.4.3 loading pickled environment... done myst v0.13.3: MdParserConfig(renderer='sphinx', commonmark_only=False, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, update_mathjax=True, enable_extensions=['colon_fence', 'dollarmath', 'linkify', 'substitution'], disable_syntax=[], url_schemes=['mailto', 'http', 'https'], heading_anchors=None, html_meta=[], footnote_transition=True, substitutions=[], sub_delimiters=['{', '}']) building [mo]: targets for 0 po files that are out of date building [html]: targets for 1 source files that are out of date updating environment: 0 added, 1 changed, 0 removed reading sources... [100%] simple
looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [100%] simple
./test/simple.md: WARNING: label 'my-table-ref' not found. ./test/simple.md:34: WARNING: Failed to create a cross reference. A title or caption not found: my-table-ref generating indices... genindex done writing additional pages... search done copying static files... done copying extra files... done dumping search index in English (code: en)... done dumping object inventory... done build succeeded, 2 warnings.

The HTML pages are in test/_build/html.

===============================================================================

Finished generating HTML for book. Your book's HTML pages are here: test/_build/html/ You can look at your book by opening this file in a browser: test/_build/html/index.html Or paste this line directly into your browser bar: file://./test/_build/html/index.html

===============================================================================

The results are as described above.

nathanael-fijalkow avatar Feb 07 '21 17:02 nathanael-fijalkow

Hi @chrisjsewell

Since then I have toyed around some more. Here is some hopefully better understanding. I have two separating issues:

  • referencing a note (as opposed to a table)
  • using a numbered reference for a table

Let me start with referencing the following note:

```{note} Title
:name: my-note-ref

Caption
```

The following work:

Here is {ref}`my reference<my-note-ref>`

Here is [My cool note](my-note-ref)

But this one does not:

Here is [](my-note-ref)

I expected from the documentation that it would give a link using the title of the note (here Title), but it does not, it seems that this behaviour is only for tables, figures, and code blocks. The same goes for numref: only tables, figures, and code blocks are numbered using numfig = True, not notes (is that right?), so numref cannot be used for notes.

For my second issue, I want to use numref for the following table:

```{table} Title
:name: my-table-ref

| header 1 | header 2 |
|---|---|
| 3 | 4 |
```

This works:

Here is {numref}`Custom Table %s text <my-table-ref>`

But this does not:

Here is {numref}`my-table-ref`      

Thanks! Nath

nathanael-fijalkow avatar Feb 10 '21 12:02 nathanael-fijalkow

FYI this is now fixed as of sphinx-design 0.3. Thanks @chrisjsewell !

firasm avatar Aug 31 '22 21:08 firasm