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

Add inside / outside margins and todo outline #18

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Tinggaard
Copy link
Collaborator

As discussed in typst/packages#1315, a port of package to allow a note outline, and usage of inside / outside margins.

It does not take text orientation into account, as it is (to my knowledge) not inferrable. I was contemplating implementing it manually, but saw that it broke the logic for drawing the notes overall, so I disregarded it.

I'm not that experienced in writing in Typst yet, so please let me know if there could be improvements :)

@ntjess
Copy link
Owner

ntjess commented Nov 25, 2024

Thanks for the PR! I'm traveling for holidays this week but should be able to review the code afterward, if that timing is ok for you

@Tinggaard
Copy link
Collaborator Author

No worries

@Tinggaard Tinggaard mentioned this pull request Nov 29, 2024
8 tasks
@Tinggaard
Copy link
Collaborator Author

Are there any updates @ntjess?

@ntjess
Copy link
Owner

ntjess commented Dec 12, 2024

Thanks for the reminder! It's been a particularly busy week for me, but I will get this reviewed tomorrow.

I appreciate your patience 🙂

@Tinggaard
Copy link
Collaborator Author

I was also considering adding additional styling to specify the size of the small upward line, as I'm fond of a smaller one in general. Like the ones shown here:
image

But I'm not 100% sure how the path drawing is achieved though, as it seemed to break the layout when I tried to change the size of the line at line 374

typst-drafting/drafting.typ

Lines 373 to 380 in 769fbbc

let path-pts = _path-from-diffs(
(0pt, -1em),
(0pt, 1em + text-offset),
(-anchor-x + props.margin-left + 1 * pct, 0pt),
(-2 * pct, 0pt),
(0pt, dy),
(-1 * pct - box-width / 2, 0pt),
)

drafting.typ Outdated Show resolved Hide resolved
drafting.typ Outdated Show resolved Hide resolved
drafting.typ Outdated Show resolved Hide resolved
drafting.typ Outdated Show resolved Hide resolved
typst.toml Show resolved Hide resolved
drafting.typ Outdated Show resolved Hide resolved
@ntjess
Copy link
Owner

ntjess commented Dec 13, 2024

I was also considering adding additional styling to specify the size of the small upward line

Something like this? Changing the property caret-height to a smaller value like 0.25em will match your image:

From 64d8c48616a8c74e1ca6e655a2fad1c99f91cd2c Mon Sep 17 00:00:00 2001
From: Nathan Jessurun <[email protected]>
Date: Thu, 12 Dec 2024 20:40:47 -0600
Subject: [PATCH] Allow configurable margin caret height

---
 drafting.typ | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drafting.typ b/drafting.typ
index a2ba157..96ca03a 100644
--- a/drafting.typ
+++ b/drafting.typ
@@ -33,6 +33,7 @@
     rect: rect,
     side: auto,
     hidden: false,
+    caret-height: 1em,
   ),
 )
 #let note-descent = state("note-descent", (:))
@@ -434,8 +435,8 @@
   let path-pts = _path-from-diffs(
     // make an upward line before coming back down to go all the way to
     // the top of the lettering
-    (0pt, -1em),
-    (0pt, 1em + text-offset),
+    (0pt, -props.caret-height),
+    (0pt, props.caret-height + text-offset),
     (dist-to-margin, 0pt),
     (0pt, dy),
     (1*pct + right-width / 2, 0pt)
@@ -464,8 +465,8 @@
   let text-offset = 0.4em
   let box-width = props.margin-left - 4 * pct
   let path-pts = _path-from-diffs(
-    (0pt, -1em),
-    (0pt, 1em + text-offset),
+    (0pt, -props.caret-height),
+    (0pt, props.caret-height + text-offset),
     (-anchor-x + props.margin-left + 1 * pct, 0pt),
     (-2 * pct, 0pt),
     (0pt, dy),
-- 
2.39.5 (Apple Git-154)

We can also have a margin-trail dict of props or something, if we want to customize more behaviors down the road

@Tinggaard
Copy link
Collaborator Author

Tinggaard commented Dec 13, 2024

Oh my, thanks for a comprehensive review!
I will get to it, but I also have plans for the weekend, so it may take a few days... Just FYI

Edit: This aged well...

Change page-binding to be `alignment`
Set default note fill to `none`
Move margin calculations to seperate function
Determine text direction based on lang
@Tinggaard
Copy link
Collaborator Author

We can also have a margin-trail dict of props or something, if we want to customize more behaviors down the road

Not entirely sure what you mean by a margin trail... Is it the path from the location in the text, to the note you wish to customize?

drafting.typ Outdated
@@ -398,7 +513,7 @@
/// - dy (length): Vertical offset from the note's location -- negative values
/// move the note up, positive values move the note down
/// - ..kwargs (dictionary): Additional properties to apply to the note. Accepted values are keys from `margin-note-defaults`.
#let margin-note(body, dy: auto, ..kwargs) = {
#let margin-note(body, dy: auto, ..kwargs) = [ #h(0pt) #{ // h(0pt) forces here().position() to take paragraph indent into account
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really happy about this approach btw, if you have a suggestion...

But setting

#set par(first-line-indent: 1em)

Results in notes in a new paragraph not being place properly

@ntjess
Copy link
Owner

ntjess commented Dec 13, 2024

Indeed — in case users want e.g. smooth radius curves instead of rectangular paths or something. Just a thought if we are providing ways to customize the path

drafting.typ Outdated Show resolved Hide resolved
drafting.typ Outdated Show resolved Hide resolved
@Tinggaard
Copy link
Collaborator Author

I've been using the @ntjess repo because it's handling right/left based on inside/outside margins, so I will provide a MRE showing the problem.

The package does currently not support inside/outside margins afaik, or am I missing something?


I see your problem @reverendpaco. The addition was made to allow for an outline entry such that all notes in the document can be listed, along with their content.
Maybe an option would be to make this feature opt-in, such that these figures are not created unless explicitly requested.

@Tinggaard
Copy link
Collaborator Author

I will see if I can make it work with labels instead of figures, as @ntjess suggested. This way the content would not be displayed twice.

@reverendpaco
Copy link

I've been using the @ntjess repo because it's handling right/left based on inside/outside margins, so I will provide a MRE showing the problem.

The package does currently not support inside/outside margins afaik, or am I missing something?

Huh.. that's funny. You're right. I have no idea how I got here then 😄 . It's especially funny because if I bothered to look at what your PR was, I could see that it has nothing to do with inside/outside auto-location.

@reverendpaco
Copy link

I've been using the @ntjess repo because it's handling right/left based on inside/outside margins, so I will provide a MRE showing the problem.

The package does currently not support inside/outside margins afaik, or am I missing something?

Huh.. that's funny. You're right. I have no idea how I got here then 😄 . It's especially funny because if I bothered to look at what your PR was, I could see that it has nothing to do with inside/outside auto-location.

Ok.. Sorry for confusing you and myself. I DO want to use your repo @Tinggaard . You are the one who introduces inside/outside margin (which I needed for my tufte-style layout). I was incorrect to say:

I've been using the @ntjess repo because it's handling right/left based on inside/outside margins

should have said:

I've been using the @Tinggaard repo because it's handling right/left based on inside/outside margins

I got your names/repos confused.

@Tinggaard
Copy link
Collaborator Author

@reverendpaco I have removed the hidden figure (#_note-outline-entry(props, body)), and queried using labels as @ntjess suggested.

I have also tested your provided MRE, and it does not create an additional footnote unless #note-outline() is invoked, creating an additional citation for the text in the outline.

@Tinggaard
Copy link
Collaborator Author

@ntjess, would you care to review again?

@ntjess
Copy link
Owner

ntjess commented Jan 13, 2025

Hey, sorry again for the delay. Yes, I'll be able to review this weekend if it's not too late? Otherwise, I can make time in the next two days.

I want to test a few edge cases which requires me to sit down and make the typst documents

@Tinggaard
Copy link
Collaborator Author

Take your time. I just wanted to make sure the PR was not forgotten :)

tests/misc.typ Outdated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tinggaard any other good things to test here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that depends on the purpose of the test...
We could basically test all the functionality in margin-note-defaults, most important is probably something like hidden and caret-height.

Also, how is the test evaluated?

let props = (
fill: note.at("fill", default: defaults.fill),
stroke: note.at("stroke", default: defaults.stroke),
body: note.at("body", default: "<body text unkonwn>"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styled notes add things to the overview. I think it's fine for now, but we can think of a future PR to grab just the text
image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tinggaard Do you think it's desirable to copy the entire stroke instead of just the paint for the outline box, which will preserve dashing etc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could consider using get.text() from t4t. This would remove all the styling at least.

I've had the same issue when using it locally and setting a smaller font-size in the notes, which makes the outline look weird if the styling is applied.

As for the stroke, I think it's nice to have the dash available, as well as possibly the thickness.

Comment on lines +367 to +378
let paint = stroke(note-props.stroke).paint
link(
note.location().position(),
grid(
columns: (1em, 1fr, 10pt),
column-gutter: 5pt,
align: (top, bottom, bottom),
box(
fill: note-props.fill,
stroke: if note-props.stroke == none {
none
} else if paint != note-props.fill {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is of lesser concern (as it seems weird to do), but this panics in the stroke constructor if note-props.stroke is none, which is possible (in the current version).

#set-margin-note-defaults(stroke: none)

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

Successfully merging this pull request may close these issues.

3 participants