DND-5e-LaTeX-Template icon indicating copy to clipboard operation
DND-5e-LaTeX-Template copied to clipboard

Add anchor to DndMonster environment

Open timvdalen opened this issue 2 years ago • 8 comments

Because the DndMonster environment doesn't place an anchor, it's currently not possible to refer to it. A possible workaround is by adding a \phantomsection to the monster.

Properly anchoring the DndMonster environment would allow stuff like \nameref{} to work as well.

timvdalen avatar Jan 16 '22 18:01 timvdalen

I just handle the links myself. This is how my statblocks all start:

\begin{WbsStatBlock}{\pagetarget{npc:couatl}{Couatl}}
  \DndMonsterType{Medium celestial, lawful good}

WbsStatBlock encapsulates DndMonsterNoBg with custom styling. \pagetarget is a function I added that sets a reference, and a corresponding \pagelink links to the reference, emitting a hyperlink in PDFs and a "p. ##" in print on demand.

We have generally avoided auto-linking because of the chance of characters in the name which would not be valid in the anchor. Setting the reference myself allows me to avoid illegal characters and simplify the link. If illegal characters are automatically stripped, there is a small chance of a collision in the references of two similarly named creatures. Adding an argument which forces the reference to a value would avoid the collisions, and it could be set when needed.

Another hurdle is that the user might not know what illegal characters were automatically stripped, and what the resulting reference is.

Do you have some suggestions for how to go about this?

BrianCriswell avatar Jan 17 '22 14:01 BrianCriswell

Sorry, I wasn't suggesting autolinking (and I agree with your reasoning about why it doesn't make sense). Perhaps the DndMonster environment could take an optional argument label? If that's set, we could \phantomsection\label{#1}. Then you'd be able to:

\begin{DndMonster}[label=monster:wolf]
...
\end{DndMonster}

timvdalen avatar Jan 18 '22 10:01 timvdalen

So this is what I had in my class for creating cross-references (with the print on demand part stripped out).

\NewDocumentCommand {\pagetarget} { m m }
  {
    \phantomsection
    \label {#1}
    \hypertarget {#1} {#2}
  }

\NewDocumentCommand {\pagelink} { m m }
  {
    \hyperlink {#1} {#2}
  }

What would you propose for how DndMonster adds in the label, and what should a function to reference the label look like?

BrianCriswell avatar Jan 18 '22 11:01 BrianCriswell

I didn't know about hypertarget, I just reference them 'by hand' since there's usually some pluralization going on as well. For an initially worthwhile solution, I think adding \phantomsection\label{#1} to the environment (if #1 is defined) would work well enough.

Basically, as a user, I was expecting DndMonster to define a section so I could add a label to it. Perhaps just adding \phantomsection would be enough, but that might mess with people's expectations of sections.

PS. Interesting that you mention print on demand, I've actually also been working on that. I now have a class that works for Amazon KDP (including a variant of the page decorations with bleed that I'll push to my fork), would you be interested in a PR that adds a print option to the class to enable bleed and margins?

timvdalen avatar Jan 18 '22 11:01 timvdalen

Hmm, I would need to reexamine sections to get a clearer picture on what is needed.

As for PoD, I think it would need to satisfy DTRPG. Amazon's PoD service is pretty lenient and seems to accept anything that DTRPG accepts, but not the other way around.

BrianCriswell avatar Jan 18 '22 11:01 BrianCriswell

RE: PoD, for sure. I've been able to satisfy Amazon (and have made some progress for PDF/X-1a:2001 compatibility) but have not been able to crack ink coverage yet

timvdalen avatar Jan 18 '22 11:01 timvdalen

You mean where DTRPG requires <=240%? It requires making a special ICC with Photoshop. The easiest way to convert it is to use ImageMagick to convert RGB images to CMYK with the ICC. It's really surprising to me that DTRPG doesn't just supply an ICC.

I have a batch file that I run to convert all the RGB files and place them in a mirrored directory structure for the CMYK images. My LaTeX class then accepts a target argument that specifies whether the target is screen or PoD and selects the RGB or CMYK image folder accordingly.

The other thing you might run into is the no transparency requirement. I round the edges of my images with TColorBox, and this is implemented via alpha blending. I have to run one of the Adobe Acrobat proofing routines to flatten the images in the resulting PDF.

BrianCriswell avatar Jan 18 '22 11:01 BrianCriswell

At the risk of derailing this thread, would you be willing to share how you handle batch color profile conversion for images with transparency? If I let ImageMagick handle the -profile conversion from a png to a pdf, the resulting PDF file is broken in Acrobat.

I was able to make it work (and my DTRPG proof is ordered!), but I had to first convert all PNGs to PDF and then manually convert their color profiles in Acrobat.

timvdalen avatar Feb 15 '22 19:02 timvdalen