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

Option to include the section number in a cross-reference #464

Closed
vogella opened this issue May 30, 2016 · 18 comments
Closed

Option to include the section number in a cross-reference #464

vogella opened this issue May 30, 2016 · 18 comments

Comments

@vogella
Copy link
Contributor

vogella commented May 30, 2016

If the :sectnums: I think the cross-reference should include the section numbers or at least you should offer an option for it.

@mojavelinux mojavelinux changed the title Open to include the section number in a cross-reference Option to include the section number in a cross-reference May 30, 2016
@mojavelinux
Copy link
Member

In may ways, this ties back to an issue in core. See asciidoctor/asciidoctor#858.

@mojavelinux
Copy link
Member

In other words, the challenge is how and where to describe this. We know where to change the code. What we need to figure out how to tell the code what to write out.

@vogella
Copy link
Contributor Author

vogella commented May 30, 2016

I suggest to do it like DocBook

<xref linkend="tutorial__p2exportA" /> results from example in Section 31.8, “Create the initial product export” in one of my documents. I think that is a pretty decent result.

@mojavelinux
Copy link
Member

The problem is, we can't do it just one way, because different people working in different scenarios will want different behavior. We have to have a way to specify it. (I'm also thinking this is an opportunity for an extension point to make further customization possible).

@vogella
Copy link
Contributor Author

vogella commented Sep 6, 2016

Just to explain this issue a bit more. I use frequently cross-links in my printouts for example:

See <<createtemplate>> to learn how to do this. 

This may result in:

See "Creating a template folder in Android Studio" to learn how to do this. 

Unfortunately without section this is very hard to print in a > 400 pages printout. Desired would be to have the section number:

See "4.5.2 Creating a template folder in Android Studio" to learn how to do this. 

@vogella
Copy link
Contributor Author

vogella commented Nov 1, 2016

I assume

is the correct place to change this.

@fapdash
Copy link
Member

fapdash commented Nov 9, 2016

I would like to start with this. From my understanding we need to implement this in the core, so that the reftext that gets accessed by the converter is already set correctly, is that right?

reftext = node.document.references[:ids][refid]

@vogella
Copy link
Contributor Author

vogella commented Nov 9, 2016

@fap- thanks for starting to work on this. The index (recently added) and the table of context already include the section number. So I assume this information is already available for the converter and no change is required.

@mojavelinux please feel free to correct me.

@fapdash
Copy link
Member

fapdash commented Nov 10, 2016

From what I've seen the information is there but it isn't connected. (we can't get a section instance, who knows about it's sectnum, by it's refid)

asciidoctor/asciidoctor#858 and asciidoctor/asciidoctor#1132 seem to have a broader scope but I'm not sure if I understand everything correctly, as I haven't had prior experience with either AsciiDoctor or AsciiDoc.

My proposal would be to introduce {sectnum} and {sectname}.
{sectnum} getting substituted with section.sectnum and {sectname} with section.name.
So we could have:

:section-label: {chapter-label} {sectnum} {sectname} // global default

[id="X2",reftext="{chapter-label} {sectnum}"] // local
== Paragraphs

I think the right place to substitute would be in Parser.initialize_section but at this point the Section.number is still set to the default of '1' and only gets set correctly when the Section later gets added to it's parent.

@vogella
Copy link
Contributor Author

vogella commented Nov 10, 2016

@fap- maybe you can provide a PR for your suggestion? I know @mojavelinux is currently busy at the Devvox conference.

We have a clone at @vogellacompany which you can use for it. If you can adjust our Gradle script to use the vogellacompany clone, I can also test it with our PDF scripts.

@vogella
Copy link
Contributor Author

vogella commented May 9, 2017

@mojavelinux could you look at @fap- pull request? @fap- is available to adjust the pull request based on feedback from you.

@vogella
Copy link
Contributor Author

vogella commented Jun 30, 2017

Can this issue be targeted for the next pdf release? Without it references in printed material are not usable. We using a patched version with the patch from @fap- included since > 6 months and we are very happy with the result.

@mojavelinux
Copy link
Member

Absolutely. The only hold up was that we needed to set the behavior in core (which defines terminology, settings, and expectations). With that in place, it's almost trivial to add this to Asciidoctor PDF because all the hard work is done.

As you can probably tell by now, I don't add features until I can be sure they fit consistently. But when we do it right, we get a lot more than just the feature in front of us.

@mojavelinux
Copy link
Member

mojavelinux commented Jul 2, 2017

To prove my point, the way I implemented this feature in core, you don't even have to think about how to make formal cross reference text. It just happens automatically now...and it can be tuned using the xrefstyle attribute. Thus, your example from above can be written as:

:xrefstyle: full

See <<createtemplate>> to learn how to do this.

//...

==== Creating a template folder in Android Studio

And you'll see:

See Section 4.5.2, “Creating a template folder in Android Studio” to learn how to do this. 

@mojavelinux
Copy link
Member

There's still an open question about whether to allow the word "Section" to be dropped.

See 4.5.2, “Creating a template folder in Android Studio” to learn how to do this. 

As it stands now, the xref won't show the number if you unset section-caption (e.g., :!section-caption:). Perhaps we should support that scenario. wdyt?

@vogella
Copy link
Contributor Author

vogella commented Jul 2, 2017

There's still an open question about whether to allow the word "Section" to be dropped.

Would be nice to have the option to drop the "section". But having the correct section link included in the printed text is much more important, so if that is hard to do I think it is OK to have the section included.

@mojavelinux
Copy link
Member

mojavelinux commented Jul 3, 2017

Would be nice to have the option to drop the "section".

Consider that part done (in core). You just unset the section-refsig attribute. For details, see http://asciidoctor.org/docs/user-manual/#customizing-the-cross-reference-text.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jul 15, 2017
- add support for the xrefstyle attribute, which allows the style of
  cross reference text to be controlled
- add fallback to old behavior when using Asciidoctor < 1.5.6
@mojavelinux
Copy link
Member

This is now ready to test in Asciidoctor PDF. See #834.

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

No branches or pull requests

3 participants