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

Spell labels #93

Open
raphael-proust opened this issue Feb 1, 2018 · 5 comments
Open

Spell labels #93

raphael-proust opened this issue Feb 1, 2018 · 5 comments

Comments

@raphael-proust
Copy link
Contributor

It would be useful to be able to specify a label for the spells. That would allow hyperlinking from a spell list to a spell description. The following is a suggestion/use-case:

\section{Spell List}
…
\hyperlink{Some Magic}{spell:some-magic}
…

\section{Spell Descriptions}
…
\begin{spell}[label=spell:some-magic]
    {Some Magic}
    …
\end{spell}
…
@BrianCriswell
Copy link
Member

Here is some code that I can import in later. I am working on an international move, and time is in short supply!

%  
%Page target for setting up "see LINK on page ##"
%
\newcommand{\pagetarget}[2]{
\phantomsection%
\label{#1}
\hypertarget{#1}{#2}
}

\newcommand\pagelink[2]{%
\hyperlink{#1}{#2}\iftoggle{bool-bg-print}{ \textbf{\textit{pg.~\pageref{#1}}}}{}%
}

The pagetarget macro sets up both label and hypertarget. In your use case, only the hypertarget portion is useful, but pagelink could be used in an entirely different part of the book. In that case, the spell could be referenced, and if it is the print version where a hyperlink does not show up and is not useful, the page number is added for quick reference.

As for adding it the target label, is there not an easy way to convert the provided spell name to convert to lowercase and change all other punctuation to dashes?

@benwebber
Copy link
Contributor

As for adding it the target label, is there not an easy way to convert the provided spell name to convert to lowercase and change all other punctuation to dashes?

I spent a bit of time trying to figure this out. I couldn't find any packages that "slugify" a string.

It's easy to lowercase the name and replace certain characters using the \lccode trick, but you have to specify the characters yourself. I couldn't figure out a way to strip all non-alphanumeric characters.

@BrianCriswell
Copy link
Member

With the conversion to LaTeX3, this should be significantly easier whether through a regex replace or through other means. Although the ref I used in #164 doesn't do any special handling of non-alphanumeric characters.

@benwebber
Copy link
Contributor

It's also easy to write a "slugify" function in Lua and use LuaTeX (I've done this locally). I've also used Lua to replace the dice calculations (it's faster than fp and xfp/LaTeX3). Better LuaTeX support (rather, taking advantage of it) is one of my goals for this package.

@BrianCriswell
Copy link
Member

Maybe it would work better to just add an option for the link text? Then the function will take care of the busywork but allow the user to set define the text.

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