Commit d49c433249

d49c4332498ef3b0882640fcd0ff5d41990cd93b

parent: a35da9b282

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-11 13:17 UTC

LaTeX fragment preview

- New dependency: SwiftMath 1.7.3 (MIT), which typesets the math with its bundled math fonts (about 7 MB); scripts/build-app.sh copies its bundle into Contents/Resources, the iOS script copies bundles already.
- LatexPreview (OrgPresentation): fragments and environments in the tree, delimiters stripped, equation/align/gather mapped to what SwiftMath reads; renderings cached.
- Mac and iOS editors: org.latex-preview (C-c C-x C-l) shows previews for the buffer; fragments are hidden and as wide as their image, drawn on the baseline; environments are drawn over their lines; the caret's line shows the source.
- #+STARTUP: latexpreview / nolatexpreview and org-startup-with-latex-preview (imported from Emacs).

Closes #37

Layout: unified · split

Package.resolved +10 −1
@@ -1,5 +1,5 @@
1{ 1{
2 "originHash" : "13a9fcac60cd27fea1022731e52b785749d4a9dfb56c2e629b61c25a99e5464d", 2 "originHash" : "d7e0b26d55cadd2650ba9cd793d3473cbc2976d7fd8c46369c2ff851255998d3",
3 "pins" : [ 3 "pins" : [
4 { 4 {
5 "identity" : "grdb.swift", 5 "identity" : "grdb.swift",
@@ -28,6 +28,15 @@
28 "version" : "0.25.0" 28 "version" : "0.25.0"
29 } 29 }
30 }, 30 },
31 {
32 "identity" : "swiftmath",
33 "kind" : "remoteSourceControl",
34 "location" : "https://github.com/mgriebling/SwiftMath",
35 "state" : {
36 "revision" : "fa8244ed032f4a1ade4cb0571bf87d2f1a9fd2d7",
37 "version" : "1.7.3"
38 }
39 },
31 { 40 {
32 "identity" : "tree-sitter", 41 "identity" : "tree-sitter",
33 "kind" : "remoteSourceControl", 42 "kind" : "remoteSourceControl",
Package.swift +2 −1
@@ -25,6 +25,7 @@ let package = Package(
25 ], 25 ],
26 dependencies: [ 26 dependencies: [
27 .package(url: "https://github.com/groue/GRDB.swift", from: "7.11.1"), 27 .package(url: "https://github.com/groue/GRDB.swift", from: "7.11.1"),
28 .package(url: "https://github.com/mgriebling/SwiftMath", exact: "1.7.3"),
28 .package(url: "https://github.com/sparkle-project/Sparkle", from: "2.7.0"), 29 .package(url: "https://github.com/sparkle-project/Sparkle", from: "2.7.0"),
29 .package(url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.25.0"), 30 .package(url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.25.0"),
30 .package(url: "https://github.com/tree-sitter/tree-sitter-bash", exact: "0.25.1"), 31 .package(url: "https://github.com/tree-sitter/tree-sitter-bash", exact: "0.25.1"),
@@ -49,7 +50,7 @@ let package = Package(
49 .target(name: "OrgDocument", dependencies: ["OrgCore"]), 50 .target(name: "OrgDocument", dependencies: ["OrgCore"]),
50 .target(name: "OrgIndex", dependencies: ["OrgCore", .product(name: "GRDB", package: "GRDB.swift")]), 51 .target(name: "OrgIndex", dependencies: ["OrgCore", .product(name: "GRDB", package: "GRDB.swift")]),
51 .target(name: "OrgWorkspace", dependencies: ["OrgIndex"]), 52 .target(name: "OrgWorkspace", dependencies: ["OrgIndex"]),
52 .target(name: "OrgPresentation", dependencies: ["OrgCore"]), 53 .target(name: "OrgPresentation", dependencies: ["OrgCore", .product(name: "SwiftMath", package: "SwiftMath")]),
53 .target(name: "OrgEditorAppKit", dependencies: ["OrgDocument", "OrgPresentation"]), 54 .target(name: "OrgEditorAppKit", dependencies: ["OrgDocument", "OrgPresentation"]),
54 .target(name: "TreeSitterElisp", path: "Sources/TreeSitterElisp", sources: ["src/parser.c"], cSettings: [.headerSearchPath("src")]), 55 .target(name: "TreeSitterElisp", path: "Sources/TreeSitterElisp", sources: ["src/parser.c"], cSettings: [.headerSearchPath("src")]),
55 .target(name: "TreeSitterClojure", path: "Sources/TreeSitterClojure", sources: ["src/parser.c"], cSettings: [.headerSearchPath("src")]), 56 .target(name: "TreeSitterClojure", path: "Sources/TreeSitterClojure", sources: ["src/parser.c"], cSettings: [.headerSearchPath("src")]),
Sources/OrgApp/EmacsImport.swift +1 −1
@@ -494,7 +494,7 @@ public struct EmacsImport: Sendable {
494 guard let n = value.integer else { return note("not a number") } 494 guard let n = value.integer else { return note("not a number") }
495 add(name, .integer(n)) 495 add(name, .integer(n))
496 case "org-insert-heading-respect-content", "org-list-allow-alphabetical", "org-hide-emphasis-markers", "org-pretty-entities", 496 case "org-insert-heading-respect-content", "org-list-allow-alphabetical", "org-hide-emphasis-markers", "org-pretty-entities",
497 "org-cycle-hide-drawer-startup", "org-cycle-hide-block-startup", "org-use-speed-commands", "org-startup-with-inline-images", 497 "org-cycle-hide-drawer-startup", "org-cycle-hide-block-startup", "org-use-speed-commands", "org-startup-with-inline-images", "org-startup-with-latex-preview",
498 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated", 498 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated",
499 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies", 499 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies",
500 "org-agenda-todo-ignore-with-date", "org-agenda-tags-todo-honor-ignore-options", "org-clock-out-remove-zero-time-clocks", 500 "org-agenda-todo-ignore-with-date", "org-agenda-tags-todo-honor-ignore-options", "org-clock-out-remove-zero-time-clocks",
Sources/OrgApp/OrgPreferences.swift +1
@@ -35,6 +35,7 @@ public enum OrgPreferences {
35 spellCheck: bool("spellCheck", defaults) 35 spellCheck: bool("spellCheck", defaults)
36 ) 36 )
37 options.electricPair = bool("electricPair", defaults) 37 options.electricPair = bool("electricPair", defaults)
38 options.startupWithLatexPreview = bool("startupWithLatexPreview", defaults)
38 options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults) 39 options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults)
39 options.enforceTodoCheckboxDependencies = bool("enforceTodoCheckboxDependencies", defaults) 40 options.enforceTodoCheckboxDependencies = bool("enforceTodoCheckboxDependencies", defaults)
40 options.archiveLocation = string("archiveLocation", defaults).nonEmpty 41 options.archiveLocation = string("archiveLocation", defaults).nonEmpty
Sources/OrgApp/UserConfig.swift +2
@@ -145,6 +145,8 @@ public enum UserConfig {
145 comment: "type brackets, <> and quotes in pairs as electric-pair-mode does (off in plain Emacs; Doom pairs with smartparens)", legacy: ""), 145 comment: "type brackets, <> and quotes in pairs as electric-pair-mode does (off in plain Emacs; Doom pairs with smartparens)", legacy: ""),
146 Setting(section: "", key: "org-startup-with-inline-images", defaultsKey: "startupWithInlineImages", kind: .bool, fallback: .bool(false), 146 Setting(section: "", key: "org-startup-with-inline-images", defaultsKey: "startupWithInlineImages", kind: .bool, fallback: .bool(false),
147 comment: "show image links as images when a file opens; #+STARTUP: (no)inlineimages overrides", legacy: ""), 147 comment: "show image links as images when a file opens; #+STARTUP: (no)inlineimages overrides", legacy: ""),
148 Setting(section: "", key: "org-startup-with-latex-preview", defaultsKey: "startupWithLatexPreview", kind: .bool, fallback: .bool(false),
149 comment: "show LaTeX fragments as typeset math when a file opens; #+STARTUP: (no)latexpreview overrides", legacy: ""),
148 Setting(section: "", key: "org-use-speed-commands", defaultsKey: "useSpeedCommands", kind: .bool, fallback: .bool(false), 150 Setting(section: "", key: "org-use-speed-commands", defaultsKey: "useSpeedCommands", kind: .bool, fallback: .bool(false),
149 comment: "single keys at the start of a heading line run commands (n, p, t, c, …)", legacy: ""), 151 comment: "single keys at the start of a heading line run commands (n, p, t, c, …)", legacy: ""),
150 Setting(section: "", key: "org-cycle-hide-drawer-startup", defaultsKey: "hideDrawerStartup", kind: .bool, fallback: .bool(true), 152 Setting(section: "", key: "org-cycle-hide-drawer-startup", defaultsKey: "hideDrawerStartup", kind: .bool, fallback: .bool(true),
Sources/OrgCore/Commands/Command.swift +2
@@ -54,6 +54,8 @@ public struct EditingOptions: Sendable, Equatable, Codable {
54 public var useSpeedCommands: Bool 54 public var useSpeedCommands: Bool
55 /// `org-startup-with-inline-images`. 55 /// `org-startup-with-inline-images`.
56 public var startupWithInlineImages: Bool 56 public var startupWithInlineImages: Bool
57 /// `org-startup-with-latex-preview`.
58 public var startupWithLatexPreview = false
57 /// `org-startup-indented`: org-indent's virtual indentation. 59 /// `org-startup-indented`: org-indent's virtual indentation.
58 public var startupIndented = true 60 public var startupIndented = true
59 /// `org-hide-leading-stars`; org-indent hides them too. 61 /// `org-hide-leading-stars`; org-indent hides them too.
Sources/OrgCore/Keymap/PresetEmacs.swift +3
@@ -191,6 +191,9 @@ extension KeymapPreset {
191 keys = "C-c C-x C-v" 191 keys = "C-c C-x C-v"
192 command = "org.toggle-inline-images" 192 command = "org.toggle-inline-images"
193 [[bind]] 193 [[bind]]
194 keys = "C-c C-x C-l"
195 command = "org.latex-preview"
196 [[bind]]
194 keys = "C-c C-x C-c" 197 keys = "C-c C-x C-c"
195 command = "org.columns" 198 command = "org.columns"
196 [[bind]] 199 [[bind]]
Sources/OrgEditorAppKit/EditorCommands.swift +1
@@ -45,6 +45,7 @@ public enum EditorCommands {
45 EditorCommand(id: "org.widen", title: "Widen", action: .view), 45 EditorCommand(id: "org.widen", title: "Widen", action: .view),
46 EditorCommand(id: "org.narrow.toggle", title: "Narrow to Subtree or Widen", action: .view), 46 EditorCommand(id: "org.narrow.toggle", title: "Narrow to Subtree or Widen", action: .view),
47 EditorCommand(id: "org.toggle-inline-images", title: "Show or Hide Inline Images", action: .view), 47 EditorCommand(id: "org.toggle-inline-images", title: "Show or Hide Inline Images", action: .view),
48 EditorCommand(id: "org.latex-preview", title: "Show or Hide LaTeX Previews", action: .view),
48 EditorCommand(id: "editor.complete", title: "Complete at Point", action: .view), 49 EditorCommand(id: "editor.complete", title: "Complete at Point", action: .view),
49 EditorCommand(id: "editor.toggle-spell-check", title: "Check Spelling While Typing", action: .view), 50 EditorCommand(id: "editor.toggle-spell-check", title: "Check Spelling While Typing", action: .view),
50 EditorCommand(id: "editor.toggle-truncate-lines", title: "Truncate or Wrap Long Lines", action: .view), 51 EditorCommand(id: "editor.toggle-truncate-lines", title: "Truncate or Wrap Long Lines", action: .view),
Sources/OrgEditorAppKit/Fragments.swift +63
@@ -1,5 +1,6 @@
1#if os(macOS) 1#if os(macOS)
2import AppKit 2import AppKit
3import OrgPresentation
3 4
4/// A line of a block, on a band across the whole width of the view, as Emacs extends the 5/// A line of a block, on a band across the whole width of the view, as Emacs extends the
5/// `org-block` face. 6/// `org-block` face.
@@ -46,6 +47,68 @@ extension NSAttributedString.Key {
46 static let orgEntityDisplay = NSAttributedString.Key("OrgEntityDisplay") 47 static let orgEntityDisplay = NSAttributedString.Key("OrgEntityDisplay")
47 /// The image an image link's line shows under it. 48 /// The image an image link's line shows under it.
48 static let orgImage = NSAttributedString.Key("OrgImage") 49 static let orgImage = NSAttributedString.Key("OrgImage")
50 /// A LaTeX fragment's typeset math, on its first character.
51 static let orgLatex = NSAttributedString.Key("OrgLatex")
52}
53
54final class LatexBox: NSObject, @unchecked Sendable {
55 let rendering: LatexPreview.Rendering
56 /// An environment's image sits at the start of its first line, under the line's top.
57 let environment: Bool
58 init(_ rendering: LatexPreview.Rendering, environment: Bool) {
59 self.rendering = rendering
60 self.environment = environment
61 }
62}
63
64/// A paragraph with LaTeX previews: each drawn where its hidden fragment starts, on the line's
65/// baseline, or at the top of an environment's first line.
66final class LatexFragment: NSTextLayoutFragment, @unchecked Sendable {
67 static func hasLatex(_ string: NSAttributedString) -> Bool {
68 var found = false
69 string.enumerateAttribute(.orgLatex, in: NSRange(location: 0, length: string.length)) { value, _, stop in
70 if value != nil { found = true; stop.pointee = true }
71 }
72 return found
73 }
74
75 /// Each preview and where it goes, in the fragment's coordinates.
76 private var boxes: [(box: LatexBox, frame: CGRect)] {
77 guard let string = (textElement as? NSTextParagraph)?.attributedString else { return [] }
78 var out: [(LatexBox, CGRect)] = []
79 string.enumerateAttribute(.orgLatex, in: NSRange(location: 0, length: string.length)) { value, range, _ in
80 guard let box = value as? LatexBox,
81 let line = textLineFragments.first(where: { NSLocationInRange(range.location, $0.characterRange) }) else { return }
82 let bounds = line.typographicBounds
83 let size = box.rendering.size
84 if box.environment {
85 out.append((box, CGRect(x: bounds.minX + line.locationForCharacter(at: range.location).x, y: bounds.minY + 2, width: size.width, height: size.height)))
86 } else {
87 let baseline = bounds.minY + line.glyphOrigin.y
88 let top = max(bounds.minY, baseline - (size.height - box.rendering.descent))
89 out.append((box, CGRect(x: bounds.minX + line.locationForCharacter(at: range.location).x, y: top, width: size.width, height: size.height)))
90 }
91 }
92 return out
93 }
94
95 override var renderingSurfaceBounds: CGRect {
96 boxes.reduce(super.renderingSurfaceBounds) { $0.union($1.frame) }
97 }
98
99 override func draw(at point: CGPoint, in context: CGContext) {
100 super.draw(at: point, in: context)
101 EntityFragment.drawEntities(of: self, at: point, in: context)
102 for (box, frame) in boxes {
103 let rect = frame.offsetBy(dx: point.x, dy: point.y)
104 context.saveGState()
105 // The context is flipped; the image is drawn upright.
106 context.translateBy(x: rect.minX, y: rect.maxY)
107 context.scaleBy(x: 1, y: -1)
108 context.draw(box.rendering.image, in: CGRect(origin: .zero, size: rect.size))
109 context.restoreGState()
110 }
111 }
49} 112}
50 113
51final class InlineImageBox: NSObject, @unchecked Sendable { 114final class InlineImageBox: NSObject, @unchecked Sendable {
Sources/OrgEditorAppKit/OrgEditor+Latex.swift added +62
@@ -0,0 +1,62 @@
1#if os(macOS)
2import AppKit
3import OrgCore
4import OrgPresentation
5
6extension OrgEditor {
7 // MARK: - LaTeX previews
8
9 /// `org-latex-preview` over the whole buffer: fragments and environments show as typeset
10 /// math, except on the caret's line.
11 func toggleLatex() {
12 showsLatex.toggle()
13 refreshImages()
14 if showsLatex {
15 let count = LatexPreview.fragments(document.tree, in: 0..<utf16Length).count
16 onMessage?("\(count) LaTeX \(count == 1 ? "fragment" : "fragments") previewed")
17 } else {
18 onMessage?("LaTeX previews removed")
19 }
20 }
21
22 /// Each fragment's text hidden, as wide as its image, which `LatexFragment` draws; an
23 /// environment's image covers its lines.
24 func applyLatex(_ range: Range<Int>, in storage: NSTextStorage, revealed: NSRange) {
25 guard showsLatex, isOrg else { return }
26 let text = storage.string as NSString
27 let scale = textView.window?.backingScaleFactor ?? 2
28 let lineHeight = theme.font.ascender - theme.font.descender + theme.font.leading
29 // The image is drawn in the appearance's color of the moment.
30 var color = theme.foreground
31 textView.effectiveAppearance.performAsCurrentDrawingAppearance { color = theme.foreground.usingColorSpace(.sRGB) ?? .textColor }
32 for fragment in LatexPreview.fragments(document.tree, in: range) {
33 let r = NSRange(fragment.range)
34 guard r.length > 0, NSMaxRange(r) <= text.length, shaded.containing(r.location) == nil else { continue }
35 let lines = text.lineRange(for: r)
36 if NSLocationInRange(revealed.location, lines) || NSIntersectionRange(lines, revealed).length > 0 { continue }
37 guard let rendering = LatexPreview.render(fragment.latex, display: fragment.display, fontSize: theme.font.pointSize,
38 color: color, scale: scale) else { continue }
39 // Pretty entities in the source would draw over the image.
40 storage.removeAttribute(.orgEntityDisplay, range: r)
41 storage.addAttribute(.orgLatex, value: LatexBox(rendering, environment: fragment.environment), range: NSRange(location: r.location, length: 1))
42 if fragment.environment {
43 // The lines keep their height, under the image; a taller image makes room after them.
44 storage.addAttributes([.foregroundColor: NSColor.clear, .underlineStyle: 0], range: r)
45 let last = text.lineRange(for: NSRange(location: NSMaxRange(r) - 1, length: 0))
46 let count = text.substring(with: lines).components(separatedBy: "\n").count - (text.substring(with: lines).hasSuffix("\n") ? 1 : 0)
47 let style = (storage.attribute(.paragraphStyle, at: last.location, effectiveRange: nil) as? NSParagraphStyle)?.mutableCopy() as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
48 style.paragraphSpacing = max(style.paragraphSpacing, rendering.size.height + 4 - CGFloat(count) * (lineHeight + style.lineSpacing))
49 storage.addAttribute(.paragraphStyle, value: style, range: last)
50 } else {
51 storage.addAttributes(theme.hidden, range: r)
52 let hiddenWidth = text.substring(with: r).size(withAttributes: [.font: theme.hidden[.font] as! NSFont]).width
53 storage.addAttribute(.kern, value: max(0, rendering.size.width - hiddenWidth), range: NSRange(location: NSMaxRange(r) - 1, length: 1))
54 let line = text.lineRange(for: NSRange(location: r.location, length: 0))
55 let style = (storage.attribute(.paragraphStyle, at: line.location, effectiveRange: nil) as? NSParagraphStyle)?.mutableCopy() as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
56 style.minimumLineHeight = max(style.minimumLineHeight, lineHeight, rendering.ascent + rendering.descent + 2)
57 storage.addAttribute(.paragraphStyle, value: style, range: line)
58 }
59 }
60 }
61}
62#endif
Sources/OrgEditorAppKit/OrgEditor+Styling.swift +3 −1
@@ -47,6 +47,7 @@ extension OrgEditor {
47 applyShrunk(range, in: storage) 47 applyShrunk(range, in: storage)
48 applyHighlights(range, in: storage) 48 applyHighlights(range, in: storage)
49 applyImages(range, in: storage, revealed: revealed) 49 applyImages(range, in: storage, revealed: revealed)
50 applyLatex(range, in: storage, revealed: revealed)
50 } 51 }
51 52
52 /// `org-pretty-entities`: entities drawn as their character over the entity's last 53 /// `org-pretty-entities`: entities drawn as their character over the entity's last
@@ -78,7 +79,8 @@ extension OrgEditor {
78 79
79 /// Moving to another line shows its markup and hides the last one's. 80 /// Moving to another line shows its markup and hides the last one's.
80 func revealCaretLine() { 81 func revealCaretLine() {
81 guard !showMarkup, isOrg else { return } 82 // LaTeX previews show their source on the caret's line whether or not markup shows.
83 guard !showMarkup || showsLatex, isOrg else { return }
82 let line = caretLine 84 let line = caretLine
83 guard line != revealedLine else { return } 85 guard line != revealedLine else { return }
84 let text = textView.string as NSString 86 let text = textView.string as NSString
Sources/OrgEditorAppKit/OrgEditor.swift +7
@@ -120,6 +120,7 @@ public final class OrgEditor: NSObject {
120 if startup.folds != FoldState() { setFolds(startup.folds, wrappers: startup.wrappers) } 120 if startup.folds != FoldState() { setFolds(startup.folds, wrappers: startup.wrappers) }
121 shrunk = ShrunkColumns.startup(document.tree) 121 shrunk = ShrunkColumns.startup(document.tree)
122 if startup.inlineImages { showsImages = true } 122 if startup.inlineImages { showsImages = true }
123 if startup.latexPreview { showsLatex = true }
123 if startup.alignTables { _ = perform(AlignAllTables()) } 124 if startup.alignTables { _ = perform(AlignAllTables()) }
124 if !indented || !hideStars { restyleOutsideEditing(0..<utf16Length) } 125 if !indented || !hideStars { restyleOutsideEditing(0..<utf16Length) }
125 } 126 }
@@ -532,6 +533,7 @@ public final class OrgEditor: NSObject {
532 case "org.fold.toggle", "org.fold.open", "org.fold.close": fold(id) 533 case "org.fold.toggle", "org.fold.open", "org.fold.close": fold(id)
533 case "org.narrow.subtree", "org.narrow.block", "org.narrow.toggle", "org.widen": narrow(id) 534 case "org.narrow.subtree", "org.narrow.block", "org.narrow.toggle", "org.widen": narrow(id)
534 case "org.toggle-inline-images": toggleImages() 535 case "org.toggle-inline-images": toggleImages()
536 case "org.latex-preview": toggleLatex()
535 case "editor.toggle-spell-check": toggleSpellCheck() 537 case "editor.toggle-spell-check": toggleSpellCheck()
536 case "editor.complete": completeAtPoint() 538 case "editor.complete": completeAtPoint()
537 case "editor.toggle-truncate-lines": toggleTruncateLines() 539 case "editor.toggle-truncate-lines": toggleTruncateLines()
@@ -648,6 +650,8 @@ public final class OrgEditor: NSObject {
648 650
649 /// `org-toggle-inline-images`: lines that are only an image link show the image. 651 /// `org-toggle-inline-images`: lines that are only an image link show the image.
650 public internal(set) var showsImages = false 652 public internal(set) var showsImages = false
653 /// `org-latex-preview`: LaTeX fragments show as typeset math.
654 public internal(set) var showsLatex = false
651 /// The file's folder, for relative image paths. 655 /// The file's folder, for relative image paths.
652 public var baseDirectory: URL? { 656 public var baseDirectory: URL? {
653 didSet { if showsImages, oldValue != baseDirectory { refreshImages() } } 657 didSet { if showsImages, oldValue != baseDirectory { refreshImages() } }
@@ -909,6 +913,9 @@ extension OrgEditor: NSTextLayoutManagerDelegate {
909 if let paragraph = textElement as? NSTextParagraph, ImageFragment.image(paragraph.attributedString) != nil { 913 if let paragraph = textElement as? NSTextParagraph, ImageFragment.image(paragraph.attributedString) != nil {
910 return ImageFragment(textElement: textElement, range: range) 914 return ImageFragment(textElement: textElement, range: range)
911 } 915 }
916 if let paragraph = textElement as? NSTextParagraph, LatexFragment.hasLatex(paragraph.attributedString) {
917 return LatexFragment(textElement: textElement, range: range)
918 }
912 if let paragraph = textElement as? NSTextParagraph, EntityFragment.hasEntities(paragraph.attributedString) { 919 if let paragraph = textElement as? NSTextParagraph, EntityFragment.hasEntities(paragraph.attributedString) {
913 return EntityFragment(textElement: textElement, range: range) 920 return EntityFragment(textElement: textElement, range: range)
914 } 921 }
Sources/OrgPresentation/Display.swift +5 −1
@@ -13,6 +13,8 @@ public struct StartupDisplay: Sendable, Equatable {
13 public var hideStars: Bool 13 public var hideStars: Bool
14 /// `org-startup-with-inline-images` (`inlineimages`, `noinlineimages`). 14 /// `org-startup-with-inline-images` (`inlineimages`, `noinlineimages`).
15 public var inlineImages: Bool 15 public var inlineImages: Bool
16 /// `org-startup-with-latex-preview` (`latexpreview`, `nolatexpreview`).
17 public var latexPreview = false
16 /// `org-startup-align-all-tables` (`align`, `noalign`). 18 /// `org-startup-align-all-tables` (`align`, `noalign`).
17 public var alignTables: Bool 19 public var alignTables: Bool
18 /// `org-startup-truncated`. 20 /// `org-startup-truncated`.
@@ -30,7 +32,7 @@ extension Presentation {
30 } 32 }
31 let wrappers = startupWrappers(tree, hideDrawers: options.hideDrawerStartup, hideBlocks: options.hideBlockStartup) 33 let wrappers = startupWrappers(tree, hideDrawers: options.hideDrawerStartup, hideBlocks: options.hideBlockStartup)
32 folds.wrapperFolds = Set(wrappers.map(\.start)) 34 folds.wrapperFolds = Set(wrappers.map(\.start))
33 return StartupDisplay( 35 var display = StartupDisplay(
34 folds: folds, wrappers: wrappers, 36 folds: folds, wrappers: wrappers,
35 indented: words.contains("indent") ? true : words.contains("noindent") ? false : options.startupIndented, 37 indented: words.contains("indent") ? true : words.contains("noindent") ? false : options.startupIndented,
36 hideStars: words.contains("hidestars") ? true : words.contains("showstars") ? false : options.hideLeadingStars, 38 hideStars: words.contains("hidestars") ? true : words.contains("showstars") ? false : options.hideLeadingStars,
@@ -38,6 +40,8 @@ extension Presentation {
38 alignTables: words.contains("align") || (options.startupAlignAllTables && !words.contains("noalign")), 40 alignTables: words.contains("align") || (options.startupAlignAllTables && !words.contains("noalign")),
39 truncated: options.startupTruncated 41 truncated: options.startupTruncated
40 ) 42 )
43 display.latexPreview = startupLatexPreview(tree) ?? options.startupWithLatexPreview
44 return display
41 } 45 }
42 46
43 /// Whether `role` hides while markup is hidden: link brackets and targets as with 47 /// Whether `role` hides while markup is hidden: link brackets and targets as with
Sources/OrgPresentation/LatexPreview.swift added +139
@@ -0,0 +1,139 @@
1import CoreGraphics
2import Foundation
3import OrgCore
4import SwiftMath
5#if os(macOS)
6import AppKit
7#else
8import UIKit
9#endif
10
11/// `org-latex-preview`: LaTeX fragments and environments drawn as typeset math, by SwiftMath
12/// rather than LaTeX, so it works without TeX and on iOS.
13public enum LatexPreview {
14 /// A fragment or environment and what to typeset.
15 public struct Fragment: Equatable, Sendable {
16 public let range: Range<Int>
17 public let latex: String
18 /// `$$…$$`, `\[…\]` and environments: display style.
19 public let display: Bool
20 /// A LaTeX environment, which takes lines of its own.
21 public let environment: Bool
22 }
23
24 /// The fragments and environments that overlap `range`.
25 public static func fragments(_ tree: OrgTree, in range: Range<Int>) -> [Fragment] {
26 var out: [Fragment] = []
27 func walk(_ node: SyntaxNode) {
28 guard node.range.overlaps(range) || node.range.isEmpty && range.contains(node.range.lowerBound) else { return }
29 switch node.kind {
30 case .latexFragment:
31 if let fragment = fragment(node.text, range: node.range) { out.append(fragment) }
32 case .latexEnvironment:
33 let text = node.text.trimmingCharacters(in: .whitespacesAndNewlines)
34 let leading = node.text.prefix { $0 == " " || $0 == "\t" }.utf16.count
35 let end = node.range.lowerBound + leading + (text as NSString).length
36 out.append(Fragment(range: (node.range.lowerBound + leading)..<end, latex: environment(text), display: true, environment: true))
37 case .block:
38 return
39 default:
40 for child in node.children { walk(child) }
41 }
42 }
43 walk(tree.root)
44 return out
45 }
46
47 /// A fragment's math without its delimiters.
48 static func fragment(_ text: String, range: Range<Int>) -> Fragment? {
49 let pairs: [(String, String, Bool)] = [("$$", "$$", true), ("\\[", "\\]", true), ("\\(", "\\)", false), ("$", "$", false)]
50 for (open, close, display) in pairs where text.hasPrefix(open) && text.hasSuffix(close) && text.count >= open.count + close.count {
51 let inner = String(text.dropFirst(open.count).dropLast(close.count))
52 guard inner.contains(where: { !$0.isWhitespace }) else { return nil }
53 return Fragment(range: range, latex: inner, display: display, environment: false)
54 }
55 // `\command[…]{…}`.
56 return Fragment(range: range, latex: text, display: false, environment: false)
57 }
58
59 /// An environment as SwiftMath reads it: `equation` and `displaymath` as their body,
60 /// `align` and `gather` as `aligned` and `gathered`.
61 static func environment(_ text: String) -> String {
62 guard let m = text.firstMatch(of: #/(?s)^\\begin\{([A-Za-z]+)\*?\}(.*)\\end\{\1\*?\}$/#) else { return text }
63 let body = String(m.2).trimmingCharacters(in: .whitespacesAndNewlines)
64 switch m.1 {
65 case "equation", "displaymath", "math": return body
66 case "align", "alignat", "flalign", "eqnarray": return "\\begin{aligned}" + body + "\\end{aligned}"
67 case "gather", "multline": return "\\begin{gathered}" + body + "\\end{gathered}"
68 default: return text
69 }
70 }
71
72 /// Typeset math: the image at the screen's scale, its size in points, and how far it
73 /// reaches above and below the baseline.
74 public struct Rendering: @unchecked Sendable {
75 public let image: CGImage
76 public let size: CGSize
77 public let ascent: CGFloat
78 public let descent: CGFloat
79 }
80
81 #if os(macOS)
82 public typealias Color = NSColor
83 #else
84 public typealias Color = UIColor
85 #endif
86
87 private final class Box: NSObject {
88 let rendering: Rendering?
89 init(_ rendering: Rendering?) { self.rendering = rendering }
90 }
91
92 nonisolated(unsafe) private static let cache = NSCache<NSString, Box>()
93
94 /// `latex` typeset at `fontSize` in `color`, or nil when SwiftMath can't read it.
95 @MainActor
96 public static func render(_ latex: String, display: Bool, fontSize: CGFloat, color: Color, scale: CGFloat) -> Rendering? {
97 let key = "\(display)|\(fontSize)|\(scale)|\(color.description)|\(latex)" as NSString
98 if let cached = cache.object(forKey: key) { return cached.rendering }
99 var math = MathImage(latex: latex, fontSize: fontSize, textColor: color, labelMode: display ? .display : .text, textAlignment: .left)
100 let (error, image, layout) = math.asImage()
101 var rendering: Rendering?
102 if error == nil, let image, let layout, let cg = cgImage(image, scale: scale) {
103 rendering = Rendering(image: cg, size: image.size, ascent: layout.ascent, descent: layout.descent)
104 }
105 cache.setObject(Box(rendering), forKey: key)
106 return rendering
107 }
108
109 #if os(macOS)
110 private static func cgImage(_ image: NSImage, scale: CGFloat) -> CGImage? {
111 let width = Int((image.size.width * scale).rounded(.up)), height = Int((image.size.height * scale).rounded(.up))
112 guard width > 0, height > 0,
113 let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 0,
114 space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return nil }
115 NSGraphicsContext.saveGraphicsState()
116 NSGraphicsContext.current = NSGraphicsContext(cgContext: context, flipped: false)
117 image.draw(in: CGRect(x: 0, y: 0, width: CGFloat(width), height: CGFloat(height)))
118 NSGraphicsContext.restoreGraphicsState()
119 return context.makeImage()
120 }
121 #else
122 private static func cgImage(_ image: UIImage, scale: CGFloat) -> CGImage? {
123 let format = UIGraphicsImageRendererFormat()
124 format.scale = scale
125 return UIGraphicsImageRenderer(size: image.size, format: format).image { _ in image.draw(at: .zero) }.cgImage
126 }
127 #endif
128}
129
130extension Presentation {
131 /// `#+STARTUP: latexpreview` and `nolatexpreview`, last one wins; nil without either.
132 public static func startupLatexPreview(_ tree: OrgTree) -> Bool? {
133 var shows: Bool?
134 for word in startupOptions(tree).map({ $0.lowercased() }) {
135 if word == "latexpreview" { shows = true } else if word == "nolatexpreview" { shows = false }
136 }
137 return shows
138 }
139}
Sources/OrgstarMobile/EditorScreen.swift +1 −1
@@ -589,7 +589,7 @@ struct CommandPalette: View {
589 ("app.clock.default", "Mark as Default Clock Task"), ("app.clock.resolve", "Resolve Open Clocks…"), 589 ("app.clock.default", "Mark as Default Clock Task"), ("app.clock.resolve", "Resolve Open Clocks…"),
590 ("app.refile", "Refile…"), ("app.refile.copy", "Copy to Refile Target…"), ("app.refile.goto", "Go to Refile Target…"), 590 ("app.refile", "Refile…"), ("app.refile.copy", "Copy to Refile Target…"), ("app.refile.goto", "Go to Refile Target…"),
591 ("app.toggle-markup", "Show or Hide Markup"), 591 ("app.toggle-markup", "Show or Hide Markup"),
592 ("org.toggle-inline-images", "Show or Hide Inline Images"), ("editor.toggle-truncate-lines", "Truncate or Wrap Long Lines"), 592 ("org.toggle-inline-images", "Show or Hide Inline Images"), ("org.latex-preview", "Show or Hide LaTeX Previews"), ("editor.toggle-truncate-lines", "Truncate or Wrap Long Lines"),
593 ("org.table.toggle-column-width", "Shrink or Expand Table Column"), ("org.table.shrink", "Shrink Table Columns with Widths"), 593 ("org.table.toggle-column-width", "Shrink or Expand Table Column"), ("org.table.shrink", "Shrink Table Columns with Widths"),
594 ("org.table.expand", "Expand Table Columns"), 594 ("org.table.expand", "Expand Table Columns"),
595 ("app.table-import", "Import Table from File…"), ("app.table-export", "Export Table to File…"), 595 ("app.table-import", "Import Table from File…"), ("app.table-export", "Export Table to File…"),
Sources/OrgstarMobile/MobileEditor+Latex.swift added +61
@@ -0,0 +1,61 @@
1#if os(iOS)
2import OrgCore
3import OrgPresentation
4import UIKit
5
6extension MobileEditor {
7 // MARK: - LaTeX previews
8
9 /// `org-latex-preview` over the whole buffer: fragments and environments show as typeset
10 /// math, except on the caret's line.
11 func toggleLatex() {
12 showsLatex.toggle()
13 restyleAll()
14 if showsLatex {
15 let count = LatexPreview.fragments(document.tree, in: 0..<textView.textStorage.length).count
16 onMessage?("\(count) LaTeX \(count == 1 ? "fragment" : "fragments") previewed")
17 } else {
18 onMessage?("LaTeX previews removed")
19 }
20 }
21
22 /// As the Mac editor: each fragment hidden and as wide as its image, which
23 /// `OrgLineFragment` draws; an environment's image covers its lines.
24 func applyLatex(_ range: Range<Int>, in storage: NSTextStorage, revealed: NSRange) {
25 guard showsLatex else { return }
26 let text = storage.string as NSString
27 let scale = textView.traitCollection.displayScale
28 let color = theme.foreground.resolvedColor(with: textView.traitCollection)
29 let lineHeight = theme.font.lineHeight
30 for fragment in LatexPreview.fragments(document.tree, in: range) {
31 let r = NSRange(fragment.range)
32 guard r.length > 0, NSMaxRange(r) <= text.length, shaded.containing(r.location) == nil else { continue }
33 let lines = text.lineRange(for: r)
34 if NSLocationInRange(revealed.location, lines) || NSIntersectionRange(lines, revealed).length > 0 { continue }
35 guard let rendering = LatexPreview.render(fragment.latex, display: fragment.display, fontSize: theme.font.pointSize,
36 color: color, scale: scale) else { continue }
37 // Pretty entities in the source would draw over the image.
38 storage.removeAttribute(.orgEntityDisplay, range: r)
39 storage.removeAttribute(.orgEntityColor, range: r)
40 storage.addAttribute(.orgLatex, value: LatexBox(rendering, environment: fragment.environment), range: NSRange(location: r.location, length: 1))
41 if fragment.environment {
42 storage.addAttributes([.foregroundColor: UIColor.clear, .underlineStyle: 0], range: r)
43 let last = text.lineRange(for: NSRange(location: NSMaxRange(r) - 1, length: 0))
44 let body = text.substring(with: lines)
45 let count = body.components(separatedBy: "\n").count - (body.hasSuffix("\n") ? 1 : 0)
46 let style = (storage.attribute(.paragraphStyle, at: last.location, effectiveRange: nil) as? NSParagraphStyle)?.mutableCopy() as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
47 style.paragraphSpacing = max(style.paragraphSpacing, rendering.size.height + 4 - CGFloat(count) * (lineHeight + style.lineSpacing))
48 storage.addAttribute(.paragraphStyle, value: style, range: last)
49 } else {
50 storage.addAttributes(theme.hidden, range: r)
51 let hiddenWidth = text.substring(with: r).size(withAttributes: [.font: theme.hidden[.font] as! UIFont]).width
52 storage.addAttribute(.kern, value: max(0, rendering.size.width - hiddenWidth), range: NSRange(location: NSMaxRange(r) - 1, length: 1))
53 let line = text.lineRange(for: NSRange(location: r.location, length: 0))
54 let style = (storage.attribute(.paragraphStyle, at: line.location, effectiveRange: nil) as? NSParagraphStyle)?.mutableCopy() as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
55 style.minimumLineHeight = max(style.minimumLineHeight, lineHeight, rendering.ascent + rendering.descent + 2)
56 storage.addAttribute(.paragraphStyle, value: style, range: line)
57 }
58 }
59 }
60}
61#endif
Sources/OrgstarMobile/MobileEditor+Styling.swift +3 −1
@@ -195,6 +195,7 @@ extension MobileEditor {
195 if !showMarkup, options.prettyEntities { prettify(whole, in: storage, revealed: revealed, scriptExclusions: scriptExclusions) } 195 if !showMarkup, options.prettyEntities { prettify(whole, in: storage, revealed: revealed, scriptExclusions: scriptExclusions) }
196 applyShrunk(whole, in: storage) 196 applyShrunk(whole, in: storage)
197 applyImages(whole, in: storage, revealed: revealed) 197 applyImages(whole, in: storage, revealed: revealed)
198 applyLatex(whole, in: storage, revealed: revealed)
198 storage.endEditing() 199 storage.endEditing()
199 } 200 }
200 201
@@ -235,7 +236,8 @@ extension MobileEditor {
235 236
236 /// Moving to another line shows its markup and hides the last one's. 237 /// Moving to another line shows its markup and hides the last one's.
237 func revealCaretLine() { 238 func revealCaretLine() {
238 guard !showMarkup else { return } 239 // LaTeX previews show their source on the caret's line whether or not markup shows.
240 guard !showMarkup || showsLatex else { return }
239 let line = caretLine 241 let line = caretLine
240 guard line != revealedLine else { return } 242 guard line != revealedLine else { return }
241 let text = textView.textStorage.string as NSString 243 let text = textView.textStorage.string as NSString
Sources/OrgstarMobile/MobileEditor.swift +7 −2
@@ -106,6 +106,8 @@ final class MobileEditor: NSObject, DocumentBuffer {
106 var revealedLine: NSRange? 106 var revealedLine: NSRange?
107 /// `org-toggle-inline-images`: lines that are only an image link show the image. 107 /// `org-toggle-inline-images`: lines that are only an image link show the image.
108 internal(set) var showsImages = false 108 internal(set) var showsImages = false
109 /// `org-latex-preview`: LaTeX fragments show as typeset math.
110 internal(set) var showsLatex = false
109 /// The view width images were last sized for. 111 /// The view width images were last sized for.
110 var imageWidth: CGFloat = 0 112 var imageWidth: CGFloat = 0
111 /// The file's folder, for relative image paths. 113 /// The file's folder, for relative image paths.
@@ -153,6 +155,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
153 indented = startup.indented 155 indented = startup.indented
154 hideStars = startup.hideStars 156 hideStars = startup.hideStars
155 showsImages = startup.inlineImages 157 showsImages = startup.inlineImages
158 showsLatex = startup.latexPreview
156 shrunk = ShrunkColumns.startup(document.tree) 159 shrunk = ShrunkColumns.startup(document.tree)
157 applyThemeToView() 160 applyThemeToView()
158 load(document.text) 161 load(document.text)
@@ -269,6 +272,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
269 case "org.cycle-global": cycleGlobal() 272 case "org.cycle-global": cycleGlobal()
270 case "org.link.open": openLinkAtCaret() 273 case "org.link.open": openLinkAtCaret()
271 case "org.toggle-inline-images": toggleImages() 274 case "org.toggle-inline-images": toggleImages()
275 case "org.latex-preview": toggleLatex()
272 case "editor.toggle-truncate-lines": 276 case "editor.toggle-truncate-lines":
273 truncatesLines.toggle() 277 truncatesLines.toggle()
274 onMessage?(truncatesLines ? "Truncate long lines enabled" : "Truncate long lines disabled") 278 onMessage?(truncatesLines ? "Truncate long lines enabled" : "Truncate long lines disabled")
@@ -294,7 +298,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
294 switch id { 298 switch id {
295 case "org.cycle": 299 case "org.cycle":
296 return Presentation.heading(containing: context.caret, in: context.tree) != nil || Wrappers.toggleable(at: context.caret, in: context.tree) != nil 300 return Presentation.heading(containing: context.caret, in: context.tree) != nil || Wrappers.toggleable(at: context.caret, in: context.tree) != nil
297 case "org.cycle-global", "edit.undo", "edit.redo", "org.toggle-inline-images", "editor.toggle-truncate-lines": return true 301 case "org.cycle-global", "edit.undo", "edit.redo", "org.toggle-inline-images", "org.latex-preview", "editor.toggle-truncate-lines": return true
298 case "app.clock.in", "app.clock.out", "app.clock.cancel", "app.clock.goto", "app.clock.in-recent", "app.clock.in-last", 302 case "app.clock.in", "app.clock.out", "app.clock.cancel", "app.clock.goto", "app.clock.in-recent", "app.clock.in-last",
299 "app.clock.goto-recent", "app.clock.default", "app.clock.resolve", "app.toggle-markup": return onAppCommand != nil 303 "app.clock.goto-recent", "app.clock.default", "app.clock.resolve", "app.toggle-markup": return onAppCommand != nil
300 case "app.refile.goto", "app.table-import": return onAppCommand != nil 304 case "app.refile.goto", "app.table-import": return onAppCommand != nil
@@ -549,7 +553,8 @@ extension MobileEditor: NSTextLayoutManagerDelegate {
549 let string = (textElement as? NSTextParagraph)?.attributedString 553 let string = (textElement as? NSTextParagraph)?.attributedString
550 let image = string.flatMap(OrgLineFragment.image) 554 let image = string.flatMap(OrgLineFragment.image)
551 let entities = string.map(OrgLineFragment.hasEntities) ?? false 555 let entities = string.map(OrgLineFragment.hasEntities) ?? false
552 guard folded || band != nil || image != nil || entities else { return NSTextLayoutFragment(textElement: textElement, range: range) } 556 let latex = string.map(OrgLineFragment.hasLatex) ?? false
557 guard folded || band != nil || image != nil || entities || latex else { return NSTextLayoutFragment(textElement: textElement, range: range) }
553 let fragment = OrgLineFragment(textElement: textElement, range: range) 558 let fragment = OrgLineFragment(textElement: textElement, range: range)
554 fragment.folded = folded 559 fragment.folded = folded
555 fragment.band = band 560 fragment.band = band
Sources/OrgstarMobile/MobileFragments.swift +46 −1
@@ -104,6 +104,18 @@ extension NSAttributedString.Key {
104 static let orgEntityColor = NSAttributedString.Key("OrgEntityColor") 104 static let orgEntityColor = NSAttributedString.Key("OrgEntityColor")
105 /// The image an image link's line shows under it. 105 /// The image an image link's line shows under it.
106 static let orgImage = NSAttributedString.Key("OrgImage") 106 static let orgImage = NSAttributedString.Key("OrgImage")
107 /// A LaTeX fragment's typeset math, on its first character.
108 static let orgLatex = NSAttributedString.Key("OrgLatex")
109}
110
111final class LatexBox: NSObject, @unchecked Sendable {
112 let rendering: LatexPreview.Rendering
113 /// An environment's image sits at the start of its first line, under the line's top.
114 let environment: Bool
115 init(_ rendering: LatexPreview.Rendering, environment: Bool) {
116 self.rendering = rendering
117 self.environment = environment
118 }
107} 119}
108 120
109final class InlineImageBox: NSObject, @unchecked Sendable { 121final class InlineImageBox: NSObject, @unchecked Sendable {
@@ -157,6 +169,35 @@ final class OrgLineFragment: NSTextLayoutFragment, @unchecked Sendable {
157 return found 169 return found
158 } 170 }
159 171
172 static func hasLatex(_ string: NSAttributedString) -> Bool {
173 var found = false
174 string.enumerateAttribute(.orgLatex, in: NSRange(location: 0, length: string.length)) { value, _, stop in
175 if value != nil { found = true; stop.pointee = true }
176 }
177 return found
178 }
179
180 /// Each LaTeX preview and where it goes: on the line's baseline where its hidden fragment
181 /// starts, or at the top of an environment's first line.
182 private var latexBoxes: [(box: LatexBox, frame: CGRect)] {
183 guard let string = (textElement as? NSTextParagraph)?.attributedString else { return [] }
184 var out: [(LatexBox, CGRect)] = []
185 string.enumerateAttribute(.orgLatex, in: NSRange(location: 0, length: string.length)) { value, range, _ in
186 guard let box = value as? LatexBox,
187 let line = textLineFragments.first(where: { NSLocationInRange(range.location, $0.characterRange) }) else { return }
188 let bounds = line.typographicBounds
189 let size = box.rendering.size
190 let x = bounds.minX + line.locationForCharacter(at: range.location).x
191 if box.environment {
192 out.append((box, CGRect(x: x, y: bounds.minY + 2, width: size.width, height: size.height)))
193 } else {
194 let baseline = bounds.minY + line.glyphOrigin.y
195 out.append((box, CGRect(x: x, y: max(bounds.minY, baseline - (size.height - box.rendering.descent)), width: size.width, height: size.height)))
196 }
197 }
198 return out
199 }
200
160 static func hasEntities(_ string: NSAttributedString) -> Bool { 201 static func hasEntities(_ string: NSAttributedString) -> Bool {
161 var found = false 202 var found = false
162 string.enumerateAttribute(.orgEntityDisplay, in: NSRange(location: 0, length: string.length)) { value, _, stop in 203 string.enumerateAttribute(.orgEntityDisplay, in: NSRange(location: 0, length: string.length)) { value, _, stop in
@@ -182,7 +223,7 @@ final class OrgLineFragment: NSTextLayoutFragment, @unchecked Sendable {
182 override var renderingSurfaceBounds: CGRect { 223 override var renderingSurfaceBounds: CGRect {
183 var bounds = super.renderingSurfaceBounds 224 var bounds = super.renderingSurfaceBounds
184 if folded { bounds = bounds.insetBy(dx: -40, dy: 0).offsetBy(dx: 40, dy: 0) } 225 if folded { bounds = bounds.insetBy(dx: -40, dy: 0).offsetBy(dx: 40, dy: 0) }
185 for rect in [bandRect, imageRect].compactMap({ $0 }) { bounds = bounds.union(rect) } 226 for rect in [bandRect, imageRect].compactMap({ $0 }) + latexBoxes.map(\.frame) { bounds = bounds.union(rect) }
186 return bounds 227 return bounds
187 } 228 }
188 229
@@ -199,6 +240,10 @@ final class OrgLineFragment: NSTextLayoutFragment, @unchecked Sendable {
199 defer { UIGraphicsPopContext() } 240 defer { UIGraphicsPopContext() }
200 drawEntities(at: point) 241 drawEntities(at: point)
201 if let image, let rect = imageRect { image.image.draw(in: rect.offsetBy(dx: point.x, dy: point.y)) } 242 if let image, let rect = imageRect { image.image.draw(in: rect.offsetBy(dx: point.x, dy: point.y)) }
243 for (box, frame) in latexBoxes {
244 UIImage(cgImage: box.rendering.image, scale: CGFloat(box.rendering.image.width) / max(1, box.rendering.size.width), orientation: .up)
245 .draw(in: frame.offsetBy(dx: point.x, dy: point.y))
246 }
202 if folded, let line = textLineFragments.first(where: { $0.characterRange.length > 0 }) ?? textLineFragments.first { 247 if folded, let line = textLineFragments.first(where: { $0.characterRange.length > 0 }) ?? textLineFragments.first {
203 let bounds = line.typographicBounds 248 let bounds = line.typographicBounds
204 let ellipsis = NSAttributedString(string: " …", attributes: [ 249 let ellipsis = NSAttributedString(string: " …", attributes: [
Tests/OrgEditorAppKitTests/LatexPreviewEditorTests.swift added +42
@@ -0,0 +1,42 @@
1import AppKit
2import OrgCore
3@testable import OrgEditorAppKit
4import Testing
5
6@MainActor
7struct LatexPreviewEditorTests {
8 static let text = "#+STARTUP: latexpreview\n* Math\nInline $x^2$ here.\n\\begin{equation}\na = b\n\\end{equation}\nEnd.\n"
9
10 /// The layout fragment over `offset`.
11 static func fragment(_ h: Harness, at offset: Int) -> NSTextLayoutFragment? {
12 h.layout()
13 let manager = h.editor.textLayoutManager
14 let content = manager.textContentManager!
15 guard let location = content.location(content.documentRange.location, offsetBy: offset) else { return nil }
16 return manager.textLayoutFragment(for: location)
17 }
18
19 @Test func startupShowsPreviewsOffTheCaretLine() throws {
20 let h = Harness(Self.text)
21 #expect(h.editor.showsLatex)
22 let ns = Self.text as NSString
23 let dollar = ns.range(of: "$x^2$").location
24 let storage = try #require(h.textView.textStorage)
25 let box = try #require(storage.attribute(.orgLatex, at: dollar, effectiveRange: nil) as? LatexBox)
26 #expect(box.rendering.size.width > 5 && !box.environment)
27 let kern = storage.attribute(.kern, at: dollar + 4, effectiveRange: nil) as? CGFloat
28 #expect((kern ?? 0) > 5)
29 #expect(Self.fragment(h, at: dollar) is LatexFragment)
30 let begin = ns.range(of: "\\begin").location
31 #expect((storage.attribute(.orgLatex, at: begin, effectiveRange: nil) as? LatexBox)?.environment == true)
32
33 // On the caret's line, the source.
34 h.caret(at: dollar + 1)
35 h.editor.revealCaretLine()
36 #expect(storage.attribute(.orgLatex, at: dollar, effectiveRange: nil) == nil)
37
38 h.editor.run("org.latex-preview")
39 #expect(!h.editor.showsLatex)
40 #expect(storage.attribute(.orgLatex, at: begin, effectiveRange: nil) == nil)
41 }
42}
Tests/OrgPresentationTests/LatexPreviewTests.swift added +37
@@ -0,0 +1,37 @@
1import AppKit
2import OrgCore
3@testable import OrgPresentation
4import Testing
5
6@MainActor
7struct LatexPreviewTests {
8 @Test func findsFragmentsAndEnvironments() {
9 let text = """
10 #+STARTUP: latexpreview
11 * Math
12 Inline $x^2$ and \\(a+b\\), display $$\\sum_i i$$ and \\[e^{i\\pi}\\], a \\frac{1}{2} and a price of $3.
13 \\begin{align}
14 a &= b \\\\
15 c &= d
16 \\end{align}
17 #+begin_src latex
18 $not$
19 #+end_src
20 """
21 let tree = OrgParser.parse(text)
22 let found = LatexPreview.fragments(tree, in: 0..<(text as NSString).length)
23 #expect(found.map(\.latex) == ["x^2", "a+b", "\\sum_i i", "e^{i\\pi}", "\\frac{1}{2}", "\\begin{aligned}a &= b \\\\\nc &= d\\end{aligned}"])
24 #expect(found.map(\.display) == [false, false, true, true, false, true])
25 #expect(found.last?.environment == true)
26 #expect((text as NSString).substring(with: NSRange(found[0].range)) == "$x^2$")
27 #expect(Presentation.startupLatexPreview(tree) == true)
28 }
29
30 @Test func rendersMath() throws {
31 let inline = try #require(LatexPreview.render("x^2 + \\frac{a}{b}", display: false, fontSize: 13, color: .black, scale: 2))
32 #expect(inline.size.width > 20 && inline.ascent > 0 && inline.image.width == Int((inline.size.width * 2).rounded(.up)))
33 let aligned = try #require(LatexPreview.render("\\begin{aligned}a &= b \\\\ c &= d\\end{aligned}", display: true, fontSize: 13, color: .black, scale: 2))
34 #expect(aligned.size.height > inline.size.height)
35 #expect(LatexPreview.render("\\frac{a}{", display: false, fontSize: 13, color: .black, scale: 2) == nil)
36 }
37}
docs/manual/guide/02-the-editor.org +21 −1
@@ -72,9 +72,27 @@ A line shows as an image when it holds nothing but a link to an image file with
72 72
73To show images when a file opens, add =#+STARTUP: inlineimages= to the file, or set =org-startup-with-inline-images = true= in =config.toml=. =#+STARTUP: noinlineimages= turns it off for one file. 73To show images when a file opens, add =#+STARTUP: inlineimages= to the file, or set =org-startup-with-inline-images = true= in =config.toml=. =#+STARTUP: noinlineimages= turns it off for one file.
74 74
75** LaTeX previews
76
77Show or Hide LaTeX Previews (=C-c C-x C-l= in the Emacs and Doom presets, and in the command palette) draws LaTeX fragments and environments as typeset math, as =org-latex-preview= does. The echo area reports how many fragments it previewed.
78
79#+BEGIN_SRC org
80The area is $\pi r^2$, and \(\sqrt{2}\) is irrational.
81\begin{equation}
82\int_0^1 x\,dx = \frac{1}{2}
83\end{equation}
84#+END_SRC
85
86- =$…$= and =\(…\)= are typeset as inline math, =$$…$$=, =\[…\]= and environments as display math. =equation=, =align=, =gather= and their starred forms are typeset as their bodies, aligned or gathered.
87- The math is typeset by orgstar itself, with the Latin Modern Math font, in the editor's text color and size; it needs no TeX installation and works on iOS. It reads the math commands LaTeX's =amsmath= has for formulas, not packages a file loads with =#+LATEX_HEADER=. A fragment it can't read stays as text.
88- The caret's line shows the source, so you can edit it.
89- Fragments in source and example blocks aren't previewed.
90
91The command switches previews for the whole buffer; Org's =C-u= forms, which act on the section at point, aren't there. To preview when a file opens, add =#+STARTUP: latexpreview= to the file, or set =org-startup-with-latex-preview = true= in =config.toml=. =#+STARTUP: nolatexpreview= turns it off for one file. After switching between light and dark appearance, switch previews off and on to redraw them in the new color.
92
75** What isn't rendered 93** What isn't rendered
76 94
77LaTeX fragments and environments are coloured but not rendered as formulas. Images in links that have a description, and images on lines with other text, show as links. 95Images in links that have a description, and images on lines with other text, show as links.
78 96
79* Folding 97* Folding
80 98
@@ -128,6 +146,7 @@ With no =#+STARTUP= visibility option, a file opens with every heading shown. Dr
128| =indent=, =noindent= | Indent bodies under headings, or not | 146| =indent=, =noindent= | Indent bodies under headings, or not |
129| =hidestars=, =showstars= | Hide all stars but the last, or not | 147| =hidestars=, =showstars= | Hide all stars but the last, or not |
130| =inlineimages=, =noinlineimages= | Show image links as images, or not | 148| =inlineimages=, =noinlineimages= | Show image links as images, or not |
149| =latexpreview=, =nolatexpreview= | Show LaTeX fragments as typeset math, or not |
131| =align=, =noalign= | Align every table, or not (=org-startup-align-all-tables=) | 150| =align=, =noalign= | Align every table, or not (=org-startup-align-all-tables=) |
132| =shrink= | Narrow table columns that have width cookies | 151| =shrink= | Narrow table columns that have width cookies |
133 152
@@ -287,6 +306,7 @@ Wrapping is display only. To rewrap the text of a paragraph, use Org ▸ Fill Pa
287| Show Markup | View ▸ Show Markup | =⇧⌘M= | off | =show-markup= | every buffer | 306| Show Markup | View ▸ Show Markup | =⇧⌘M= | off | =show-markup= | every buffer |
288| Show Line Numbers | View ▸ Show Line Numbers | =⇧⌘L= | on | =display-line-numbers-type= | every buffer | 307| Show Line Numbers | View ▸ Show Line Numbers | =⇧⌘L= | on | =display-line-numbers-type= | every buffer |
289| Inline images | Org ▸ Show or Hide Inline Images | =C-c C-x C-v= (Emacs, Doom) | off | =org-startup-with-inline-images= | current buffer | 308| Inline images | Org ▸ Show or Hide Inline Images | =C-c C-x C-v= (Emacs, Doom) | off | =org-startup-with-inline-images= | current buffer |
309| LaTeX previews | palette | =C-c C-x C-l= (Emacs, Doom) | off | =org-startup-with-latex-preview= | current buffer |
290| Spell checking | palette | =SPC t s= (Doom) | off | =spell-check= | current buffer | 310| Spell checking | palette | =SPC t s= (Doom) | off | =spell-check= | current buffer |
291| Truncate long lines | View ▸ Truncate or Wrap Long Lines | =C-x x t= (Emacs), =SPC t w= (Doom) | off | =org-startup-truncated= | current buffer | 311| Truncate long lines | View ▸ Truncate or Wrap Long Lines | =C-x x t= (Emacs), =SPC t w= (Doom) | off | =org-startup-truncated= | current buffer |
292 312
docs/manual/guide/03-keys.org +1
@@ -792,6 +792,7 @@ When a key appears in several rows, it runs the command whose condition holds at
792| Narrow to Subtree or Widen (=org.narrow.toggle=) | — | =⌃⌘N= | — | Narrows to the subtree, or widens when already narrowed (=org-toggle-narrow-to-subtree=). | 792| Narrow to Subtree or Widen (=org.narrow.toggle=) | — | =⌃⌘N= | — | Narrows to the subtree, or widens when already narrowed (=org-toggle-narrow-to-subtree=). |
793| Sparse Tree… (=org.sparse-tree=) | =C-c /= | — | =SPC m s s= (N) | Asks for a match and shows only the matching entries and their context (=org-sparse-tree=). =C-c C-c= clears the highlights. | 793| Sparse Tree… (=org.sparse-tree=) | =C-c /= | — | =SPC m s s= (N) | Asks for a match and shows only the matching entries and their context (=org-sparse-tree=). =C-c C-c= clears the highlights. |
794| Show or Hide Inline Images (=org.toggle-inline-images=) | =C-c C-x C-v= | — | — | Shows or hides image links as images (=org-toggle-inline-images=). | 794| Show or Hide Inline Images (=org.toggle-inline-images=) | =C-c C-x C-v= | — | — | Shows or hides image links as images (=org-toggle-inline-images=). |
795| Show or Hide LaTeX Previews (=org.latex-preview=) | =C-c C-x C-l= | — | — | Shows or hides LaTeX fragments as typeset math (=org-latex-preview=). |
795 796
796** Outline: headings and subtrees 797** Outline: headings and subtrees
797 798
docs/manual/guide/13-configuration.org +5 −2
@@ -146,6 +146,7 @@ These settings have no control in the Settings window. Some are in the View menu
146| =org-hide-leading-stars= | | 146| =org-hide-leading-stars= | |
147| =org-startup-align-all-tables= | | 147| =org-startup-align-all-tables= | |
148| =org-startup-with-inline-images= | | 148| =org-startup-with-inline-images= | |
149| =org-startup-with-latex-preview= | |
149| =org-cycle-hide-drawer-startup= | | 150| =org-cycle-hide-drawer-startup= | |
150| =org-cycle-hide-block-startup= | | 151| =org-cycle-hide-block-startup= | |
151| =org-use-speed-commands= | | 152| =org-use-speed-commands= | |
@@ -213,6 +214,7 @@ A key you remove from the file goes back to its default. A key that isn't in the
213| =spell-check= | boolean | =false= | Check spelling while typing, outside code, links, dates, tags and keywords. | 214| =spell-check= | boolean | =false= | Check spelling while typing, outside code, links, dates, tags and keywords. |
214| =electric-pair-mode= | boolean | =true= | Type brackets, =<>= and quotes in pairs. Mirrors =electric-pair-mode=. | 215| =electric-pair-mode= | boolean | =true= | Type brackets, =<>= and quotes in pairs. Mirrors =electric-pair-mode=. |
215| =org-startup-with-inline-images= | boolean | =false= | Show image links as images when a file opens. =#+STARTUP: inlineimages= / =noinlineimages= override it. Mirrors =org-startup-with-inline-images=. | 216| =org-startup-with-inline-images= | boolean | =false= | Show image links as images when a file opens. =#+STARTUP: inlineimages= / =noinlineimages= override it. Mirrors =org-startup-with-inline-images=. |
217| =org-startup-with-latex-preview= | boolean | =false= | Show LaTeX fragments as typeset math when a file opens. =#+STARTUP: latexpreview= / =nolatexpreview= override it. Mirrors =org-startup-with-latex-preview=. |
216| =org-use-speed-commands= | boolean | =false= | Single keys at the start of a heading line run commands (=n=, =p=, =t=, =c=, …). Mirrors =org-use-speed-commands=. | 218| =org-use-speed-commands= | boolean | =false= | Single keys at the start of a heading line run commands (=n=, =p=, =t=, =c=, …). Mirrors =org-use-speed-commands=. |
217| =org-cycle-hide-drawer-startup= | boolean | =true= | Fold drawers when a file opens. =#+STARTUP: hidedrawers= / =nohidedrawers= override it. Mirrors =org-cycle-hide-drawer-startup=. | 219| =org-cycle-hide-drawer-startup= | boolean | =true= | Fold drawers when a file opens. =#+STARTUP: hidedrawers= / =nohidedrawers= override it. Mirrors =org-cycle-hide-drawer-startup=. |
218| =org-cycle-hide-block-startup= | boolean | =false= | Fold blocks when a file opens. =#+STARTUP: hideblocks= / =nohideblocks= override it. Mirrors =org-cycle-hide-block-startup=. | 220| =org-cycle-hide-block-startup= | boolean | =false= | Fold blocks when a file opens. =#+STARTUP: hideblocks= / =nohideblocks= override it. Mirrors =org-cycle-hide-block-startup=. |
@@ -446,6 +448,7 @@ After you change a keyword line, press =C-c C-c= on it to read the file's settin
446| =hidestars=, =showstars= | Hide leading stars or show them. | 448| =hidestars=, =showstars= | Hide leading stars or show them. |
447| =align=, =noalign= | Align every table when the file opens, or don't. | 449| =align=, =noalign= | Align every table when the file opens, or don't. |
448| =inlineimages=, =noinlineimages= | Show image links as images, or don't. | 450| =inlineimages=, =noinlineimages= | Show image links as images, or don't. |
451| =latexpreview=, =nolatexpreview= | Show LaTeX fragments as typeset math, or don't. |
449| =shrink= | Shrink table columns that have a width cookie. | 452| =shrink= | Shrink table columns that have a width cookie. |
450| =logdone=, =lognotedone=, =nologdone= | Record a time, a note, or nothing when an entry becomes done. | 453| =logdone=, =lognotedone=, =nologdone= | Record a time, a note, or nothing when an entry becomes done. |
451| =logrepeat=, =lognoterepeat=, =nologrepeat= | The same, when a repeating entry is completed. | 454| =logrepeat=, =lognoterepeat=, =nologrepeat= | The same, when a repeating entry is completed. |
@@ -455,7 +458,7 @@ After you change a keyword line, press =C-c C-c= on it to read the file's settin
455 458
456After the startup visibility, orgstar applies each heading's =VISIBILITY= property and folds subtrees tagged =ARCHIVE=, unless =showeverything= is set. 459After the startup visibility, orgstar applies each heading's =VISIBILITY= property and folds subtrees tagged =ARCHIVE=, unless =showeverything= is set.
457 460
458Completion offers every option of =org-startup-options=. Options not in the table above, such as =odd=, =entitiespretty=, =latexpreview=, =constSI= and the footnote options, are accepted and ignored. 461Completion offers every option of =org-startup-options=. Options not in the table above, such as =odd=, =entitiespretty=, =constSI= and the footnote options, are accepted and ignored.
459 462
460** Setup files 463** Setup files
461 464
@@ -526,7 +529,7 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, =
526| Emacs variable | Becomes | 529| Emacs variable | Becomes |
527|--------------------------------------------------------------------+-----------------------------------------------------------------------------------------------| 530|--------------------------------------------------------------------+-----------------------------------------------------------------------------------------------|
528| =fill-column=, =org-tags-column=, =appt-message-warning-time=, =org-deadline-warning-days= | The same key, when the value is a number | 531| =fill-column=, =org-tags-column=, =appt-message-warning-time=, =org-deadline-warning-days= | The same key, when the value is a number |
529| =org-insert-heading-respect-content=, =org-list-allow-alphabetical=, =org-hide-emphasis-markers=, =org-pretty-entities=, =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup=, =org-use-speed-commands=, =org-startup-with-inline-images=, =org-startup-indented=, =org-hide-leading-stars=, =org-startup-align-all-tables=, =org-startup-truncated= | The same key: =nil= or an empty list is =false=, anything else =true= | 532| =org-insert-heading-respect-content=, =org-list-allow-alphabetical=, =org-hide-emphasis-markers=, =org-pretty-entities=, =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup=, =org-use-speed-commands=, =org-startup-with-inline-images=, =org-startup-with-latex-preview=, =org-startup-indented=, =org-hide-leading-stars=, =org-startup-align-all-tables=, =org-startup-truncated= | The same key: =nil= or an empty list is =false=, anything else =true= |
530| =org-hide-drawer-startup=, =org-hide-block-startup= | =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup= | 533| =org-hide-drawer-startup=, =org-hide-block-startup= | =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup= |
531| =org-M-RET-may-split-line= | =org-M-RET-may-split-line=, from the =default= entry of an alist; other per-context entries aren't supported | 534| =org-M-RET-may-split-line= | =org-M-RET-may-split-line=, from the =default= entry of an alist; other per-context entries aren't supported |
532| =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= | 535| =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= |
docs/manual/guide/14-ios.org +5 −4
@@ -83,6 +83,7 @@ The editor and the reader apply these display settings; only the editor aligns t
83| =org-startup-indented= | Bodies are indented under their headings | =indent=, =noindent= | 83| =org-startup-indented= | Bodies are indented under their headings | =indent=, =noindent= |
84| =org-hide-leading-stars= | Without indentation, only a heading's last star shows | =hidestars=, =showstars= | 84| =org-hide-leading-stars= | Without indentation, only a heading's last star shows | =hidestars=, =showstars= |
85| =org-startup-with-inline-images= | Image links show as images | =inlineimages=, =noinlineimages= | 85| =org-startup-with-inline-images= | Image links show as images | =inlineimages=, =noinlineimages= |
86| =org-startup-with-latex-preview= | LaTeX fragments show as typeset math; Show or Hide LaTeX Previews in Commands switches them | =latexpreview=, =nolatexpreview= |
86| =org-startup-align-all-tables= | Every table is aligned | =align=, =noalign= | 87| =org-startup-align-all-tables= | Every table is aligned | =align=, =noalign= |
87| =org-startup-truncated= | Long lines run off the right edge, and the editor scrolls sideways | | 88| =org-startup-truncated= | Long lines run off the right edge, and the editor scrolls sideways | |
88 89
@@ -278,9 +279,9 @@ The app icon's badge counts the entries in the agenda's Overdue section that are
278 279
279* Export 280* Export
280 281
281Export (in the reader's toolbar and the editor's More menu) offers HTML, Markdown, PDF, Rich Text (RTF) and Plain Text, and Copy as Rich Text. Each opens the share sheet with a file named after the org file, which you can send to another app or keep with Save to Files. The export reads the file's setup files and follows its export keywords, as the Mac's export does. 282Export (in the reader's toolbar and the editor's More menu) offers HTML, Markdown, PDF, Word, Rich Text (RTF), Plain Text and iCalendar, and Copy as Rich Text. Each opens the share sheet with a file named after the org file, which you can send to another app or keep with Save to Files. The export reads the file's setup files and follows its export keywords, as the Mac's export does.
282 283
283Word, ODT, LaTeX, ASCII and PDF through LaTeX aren't available on iOS. See [[file:12-export.org][Export]]. 284ODT, LaTeX, ASCII and PDF through LaTeX aren't available on iOS. See [[file:12-export.org][Export]].
284 285
285* Code blocks and tables 286* Code blocks and tables
286 287
@@ -344,7 +345,7 @@ These settings from =config.toml= apply on iOS:
344- =org-todo-keywords=, =org-list-allow-alphabetical= 345- =org-todo-keywords=, =org-list-allow-alphabetical=
345- =org-tags-column=, =org-insert-heading-respect-content=, =org-M-RET-may-split-line=, =fill-column= 346- =org-tags-column=, =org-insert-heading-respect-content=, =org-M-RET-may-split-line=, =fill-column=
346- =org-hide-emphasis-markers= and =org-pretty-entities=, for what hidden markup shows and for how tag and table alignment and filling measure text, as on the Mac 347- =org-hide-emphasis-markers= and =org-pretty-entities=, for what hidden markup shows and for how tag and table alignment and filling measure text, as on the Mac
347- =show-markup=, =org-startup-indented=, =org-hide-leading-stars=, =org-startup-with-inline-images=, =org-startup-align-all-tables=, =org-startup-truncated=, =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup= 348- =show-markup=, =org-startup-indented=, =org-hide-leading-stars=, =org-startup-with-inline-images=, =org-startup-with-latex-preview=, =org-startup-align-all-tables=, =org-startup-truncated=, =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup=
348- =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]= 349- =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]=
349- =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer= 350- =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer=
350- =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks= 351- =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks=
@@ -368,7 +369,7 @@ Quick Look in the Files app shows org files as the HTML export renders them.
368* What the Mac has that iOS doesn't 369* What the Mac has that iOS doesn't
369 370
370- Running code blocks in languages other than Emacs Lisp, Emacs Lisp beyond orgstar's interpreter, and tables that need Emacs. 371- Running code blocks in languages other than Emacs Lisp, Emacs Lisp beyond orgstar's interpreter, and tables that need Emacs.
371- Word, ODT, LaTeX, ASCII and LaTeX-made PDF export. 372- ODT, LaTeX, ASCII and LaTeX-made PDF export, and publishing.
372- Idle detection while a clock runs. 373- Idle detection while a clock runs.
373- Import from Emacs. 374- Import from Emacs.
374- The Columns inspector, the backlinks pane, and the buffer list and tab bar. The board and column view are there (see [[file:07-agenda.org][The agenda]] and [[file:04-outlines.org][Outlines]]). 375- The Columns inspector, the backlinks pane, and the buffer list and tab bar. The board and column view are there (see [[file:07-agenda.org][The agenda]] and [[file:04-outlines.org][Outlines]]).
docs/manual/guide/15-alongside-emacs.org +1 −1
@@ -244,7 +244,7 @@ Other:
244- =C-c C-q= before the first heading (setting file tags) isn't supported. 244- =C-c C-q= before the first heading (setting file tags) isn't supported.
245- Priority ranges that aren't letters or numbers are refused. 245- Priority ranges that aren't letters or numbers are refused.
246- =#+SETUPFILE= URLs aren't fetched. 246- =#+SETUPFILE= URLs aren't fetched.
247- Most =#+STARTUP= options for footnotes, entities, LaTeX previews, numbering and odd levels are accepted and ignored; see [[file:13-configuration.org][Configuration]]. 247- Most =#+STARTUP= options for footnotes, entities, numbering and odd levels are accepted and ignored; see [[file:13-configuration.org][Configuration]].
248- =display-line-numbers-type= has no relative or visual mode. 248- =display-line-numbers-type= has no relative or visual mode.
249- The agenda's text search (see [[file:07-agenda.org][The agenda]]) covers the agenda files only: =org-agenda-text-search-extra-files= and =org-agenda-search-view-max-outline-level= aren't supported. It runs from the view menu rather than the dispatcher's =s= and =S=, and the search view's =[=, =]=, ={= and =}= keys, which add words and regexps to the search, aren't supported. 249- The agenda's text search (see [[file:07-agenda.org][The agenda]]) covers the agenda files only: =org-agenda-text-search-extra-files= and =org-agenda-search-view-max-outline-level= aren't supported. It runs from the view menu rather than the dispatcher's =s= and =S=, and the search view's =[=, =]=, ={= and =}= keys, which add words and regexps to the search, aren't supported.
250- In regexps, =\<=, =\>= and =\b= use Org's word syntax but don't find a word boundary where the script changes between two word characters, as Emacs does (for example between an emoji and a letter). 250- In regexps, =\<=, =\>= and =\b= use Org's word syntax but don't find a word boundary where the script changes between two word characters, as Emacs does (for example between an emoji and a letter).
ios/Orgstar.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +9
@@ -28,6 +28,15 @@
28 "version" : "0.25.0" 28 "version" : "0.25.0"
29 } 29 }
30 }, 30 },
31 {
32 "identity" : "swiftmath",
33 "kind" : "remoteSourceControl",
34 "location" : "https://github.com/mgriebling/SwiftMath",
35 "state" : {
36 "revision" : "fa8244ed032f4a1ade4cb0571bf87d2f1a9fd2d7",
37 "version" : "1.7.3"
38 }
39 },
31 { 40 {
32 "identity" : "tree-sitter", 41 "identity" : "tree-sitter",
33 "kind" : "remoteSourceControl", 42 "kind" : "remoteSourceControl",
scripts/build-app.sh +3
@@ -40,6 +40,9 @@ ditto "$sparkle" "$app/Contents/Frameworks/Sparkle.framework"
40otool -l "$app/Contents/MacOS/Orgstar" | grep -q '@executable_path/../Frameworks' \ 40otool -l "$app/Contents/MacOS/Orgstar" | grep -q '@executable_path/../Frameworks' \
41 || install_name_tool -add_rpath @executable_path/../Frameworks "$app/Contents/MacOS/Orgstar" 41 || install_name_tool -add_rpath @executable_path/../Frameworks "$app/Contents/MacOS/Orgstar"
42 42
43# SwiftMath's math fonts, which it finds in the app's resources.
44cp -R "$(dirname "$binary")/SwiftMath_SwiftMath.bundle" "$app/Contents/Resources/"
45
43# Updates: the appcast and its signing key, for signed builds only; a dev build never checks. 46# Updates: the appcast and its signing key, for signed builds only; a dev build never checks.
44if [ "$sign" != "-" ]; then 47if [ "$sign" != "-" ]; then
45 feed_keys=" <key>SUFeedURL</key> 48 feed_keys=" <key>SUFeedURL</key>