Skip to content

Add a way to cross-reference code in prose text #11430

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

Open
cjdb opened this issue May 20, 2023 · 7 comments
Open

Add a way to cross-reference code in prose text #11430

cjdb opened this issue May 20, 2023 · 7 comments

Comments

@cjdb
Copy link

cjdb commented May 20, 2023

Is your feature request related to a problem? Please describe.
It's sometimes easier to refer to a part of an API by describing it, rather than by directly naming it, but the C++ cross-reference directives only render in monospace font.

For example:

and the type of ``x <=> y`` :cpp:type:`can be reduced to \`\`Cat\`\`.<std::common_comparison_category>`

will be rendered as

and the type of x <=> y can be reduced to ``Cat``.

Describe the solution you'd like
It should be possible to render the above as

and the type of x <=> y can be reduced to Cat.

I noticed that there's :cpp:expr: and :cpp:texpr:. Perhaps there should be a t-prefixed cross-reference for all of the API cross-references (e.g. cpp:ttype).

@jfbu
Copy link
Contributor

jfbu commented May 20, 2023

Does using custom CSS styling help? I defined a file _static/custom.css with these contents

code.cpp-type > .pre {
   font-style: normal;
   font-family: roman;
   font-weight: normal;
   /*text-decoration: underline*/
}

as a test and it appears to work (with default html_static_path = ['_static'] in conf.py) (although the escaped ` will show literally)

(but this is limited to html builds)

@cjdb
Copy link
Author

cjdb commented May 20, 2023

Won't this apply to all :cpp:types? I'm documenting the C++ standard library---which is huge---and so I'm going to be alternating between prose and code as it makes sense.

@jfbu
Copy link
Contributor

jfbu commented May 20, 2023

Won't this apply to all :cpp:types? I'm documenting the C++ standard library---which is huge---and so I'm going to be alternating between prose and code as it makes sense.

Yes you do need a novel role for your task.

@cjdb
Copy link
Author

cjdb commented May 20, 2023

I'll probably make an extension for this soonish (it's not a high priority). Would there be any concerns with upstreaming the roles? I'd make them for all supported languages in that case, not just C++.

@AA-Turner
Copy link
Member

A thought -- could you use a custom interpreted text role and add :class: inline-text or etc to it?

xref: https://docutils.sourceforge.io/docs/ref/rst/directives.html#custom-interpreted-text-roles

A

@AA-Turner
Copy link
Member

Additionally -- I believe that using texpr should work in general -- are there cases in C++ where the general texpr role doesn't work and you need to use the specific roles?

A

@cjdb
Copy link
Author

cjdb commented May 21, 2023

A thought -- could you use a custom interpreted text role and add :class: inline-text or etc to it?

Possibly? My plan was to copy the cpp:type role and tweak it so that it could be distinct in the CSS.

Additionally -- I believe that using texpr should work in general -- are there cases in C++ where the general texpr role doesn't work and you need to use the specific roles?

I haven't come across anything yet. My understanding of texpr is that it matches names in that role against names registered with C++ directives, but I have an English sentence that needs to be linked to a cpp:type directive.

@AA-Turner AA-Turner added this to the some future version milestone Aug 11, 2023
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

No branches or pull requests

3 participants