LaTeX fragment preview !280

merged merged by cmc on 2026-10-11 13:17 UTC · krz/orgstar:issue-37 into main

28 files changed, +543 −18

Layout: unified · split

Package.resolved +10 −1
@@ -1,5 +1,5 @@
11{
2 "originHash" : "13a9fcac60cd27fea1022731e52b785749d4a9dfb56c2e629b61c25a99e5464d",
2 "originHash" : "d7e0b26d55cadd2650ba9cd793d3473cbc2976d7fd8c46369c2ff851255998d3",
33 "pins" : [
44 {
55 "identity" : "grdb.swift",
@@ -28,6 +28,15 @@
2828 "version" : "0.25.0"
2929 }
3030 },
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 },
3140 {
3241 "identity" : "tree-sitter",
3342 "kind" : "remoteSourceControl",
Package.swift +2 −1
@@ -25,6 +25,7 @@ let package = Package(
2525 ],
2626 dependencies: [
2727 .package(url: "https://github.com/groue/GRDB.swift", from: "7.11.1"),
28 .package(url: "https://github.com/mgriebling/SwiftMath", exact: "1.7.3"),
2829 .package(url: "https://github.com/sparkle-project/Sparkle", from: "2.7.0"),
2930 .package(url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.25.0"),
3031 .package(url: "https://github.com/tree-sitter/tree-sitter-bash", exact: "0.25.1"),
@@ -49,7 +50,7 @@ let package = Package(
4950 .target(name: "OrgDocument", dependencies: ["OrgCore"]),
5051 .target(name: "OrgIndex", dependencies: ["OrgCore", .product(name: "GRDB", package: "GRDB.swift")]),
5152 .target(name: "OrgWorkspace", dependencies: ["OrgIndex"]),
52 .target(name: "OrgPresentation", dependencies: ["OrgCore"]),
53 .target(name: "OrgPresentation", dependencies: ["OrgCore", .product(name: "SwiftMath", package: "SwiftMath")]),
5354 .target(name: "OrgEditorAppKit", dependencies: ["OrgDocument", "OrgPresentation"]),
5455 .target(name: "TreeSitterElisp", path: "Sources/TreeSitterElisp", sources: ["src/parser.c"], cSettings: [.headerSearchPath("src")]),
5556 .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 {
494494 guard let n = value.integer else { return note("not a number") }
495495 add(name, .integer(n))
496496 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",
498498 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated",
499499 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies",
500500 "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 {
3535 spellCheck: bool("spellCheck", defaults)
3636 )
3737 options.electricPair = bool("electricPair", defaults)
38 options.startupWithLatexPreview = bool("startupWithLatexPreview", defaults)
3839 options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults)
3940 options.enforceTodoCheckboxDependencies = bool("enforceTodoCheckboxDependencies", defaults)
4041 options.archiveLocation = string("archiveLocation", defaults).nonEmpty
Sources/OrgApp/UserConfig.swift +2
@@ -145,6 +145,8 @@ public enum UserConfig {
145145 comment: "type brackets, <> and quotes in pairs as electric-pair-mode does (off in plain Emacs; Doom pairs with smartparens)", legacy: ""),
146146 Setting(section: "", key: "org-startup-with-inline-images", defaultsKey: "startupWithInlineImages", kind: .bool, fallback: .bool(false),
147147 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: ""),
148150 Setting(section: "", key: "org-use-speed-commands", defaultsKey: "useSpeedCommands", kind: .bool, fallback: .bool(false),
149151 comment: "single keys at the start of a heading line run commands (n, p, t, c, …)", legacy: ""),
150152 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 {
5454 public var useSpeedCommands: Bool
5555 /// `org-startup-with-inline-images`.
5656 public var startupWithInlineImages: Bool
57 /// `org-startup-with-latex-preview`.
58 public var startupWithLatexPreview = false
5759 /// `org-startup-indented`: org-indent's virtual indentation.
5860 public var startupIndented = true
5961 /// `org-hide-leading-stars`; org-indent hides them too.
Sources/OrgCore/Keymap/PresetEmacs.swift +3
@@ -191,6 +191,9 @@ extension KeymapPreset {
191191 keys = "C-c C-x C-v"
192192 command = "org.toggle-inline-images"
193193 [[bind]]
194 keys = "C-c C-x C-l"
195 command = "org.latex-preview"
196 [[bind]]
194197 keys = "C-c C-x C-c"
195198 command = "org.columns"
196199 [[bind]]
Sources/OrgEditorAppKit/EditorCommands.swift +1
@@ -45,6 +45,7 @@ public enum EditorCommands {
4545 EditorCommand(id: "org.widen", title: "Widen", action: .view),
4646 EditorCommand(id: "org.narrow.toggle", title: "Narrow to Subtree or Widen", action: .view),
4747 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),
4849 EditorCommand(id: "editor.complete", title: "Complete at Point", action: .view),
4950 EditorCommand(id: "editor.toggle-spell-check", title: "Check Spelling While Typing", action: .view),
5051 EditorCommand(id: "editor.toggle-truncate-lines", title: "Truncate or Wrap Long Lines", action: .view),
Sources/OrgEditorAppKit/Fragments.swift +63
@@ -1,5 +1,6 @@
11#if os(macOS)
22import AppKit
3import OrgPresentation
34
45/// A line of a block, on a band across the whole width of the view, as Emacs extends the
56/// `org-block` face.
@@ -46,6 +47,68 @@ extension NSAttributedString.Key {
4647 static let orgEntityDisplay = NSAttributedString.Key("OrgEntityDisplay")
4748 /// The image an image link's line shows under it.
4849 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 }
49112}
50113
51114final 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 {
4747 applyShrunk(range, in: storage)
4848 applyHighlights(range, in: storage)
4949 applyImages(range, in: storage, revealed: revealed)
50 applyLatex(range, in: storage, revealed: revealed)
5051 }
5152
5253 /// `org-pretty-entities`: entities drawn as their character over the entity's last
@@ -78,7 +79,8 @@ extension OrgEditor {
7879
7980 /// Moving to another line shows its markup and hides the last one's.
8081 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 }
8284 let line = caretLine
8385 guard line != revealedLine else { return }
8486 let text = textView.string as NSString
Sources/OrgEditorAppKit/OrgEditor.swift +7
@@ -120,6 +120,7 @@ public final class OrgEditor: NSObject {
120120 if startup.folds != FoldState() { setFolds(startup.folds, wrappers: startup.wrappers) }
121121 shrunk = ShrunkColumns.startup(document.tree)
122122 if startup.inlineImages { showsImages = true }
123 if startup.latexPreview { showsLatex = true }
123124 if startup.alignTables { _ = perform(AlignAllTables()) }
124125 if !indented || !hideStars { restyleOutsideEditing(0..<utf16Length) }
125126 }
@@ -532,6 +533,7 @@ public final class OrgEditor: NSObject {
532533 case "org.fold.toggle", "org.fold.open", "org.fold.close": fold(id)
533534 case "org.narrow.subtree", "org.narrow.block", "org.narrow.toggle", "org.widen": narrow(id)
534535 case "org.toggle-inline-images": toggleImages()
536 case "org.latex-preview": toggleLatex()
535537 case "editor.toggle-spell-check": toggleSpellCheck()
536538 case "editor.complete": completeAtPoint()
537539 case "editor.toggle-truncate-lines": toggleTruncateLines()
@@ -648,6 +650,8 @@ public final class OrgEditor: NSObject {
648650
649651 /// `org-toggle-inline-images`: lines that are only an image link show the image.
650652 public internal(set) var showsImages = false
653 /// `org-latex-preview`: LaTeX fragments show as typeset math.
654 public internal(set) var showsLatex = false
651655 /// The file's folder, for relative image paths.
652656 public var baseDirectory: URL? {
653657 didSet { if showsImages, oldValue != baseDirectory { refreshImages() } }
@@ -909,6 +913,9 @@ extension OrgEditor: NSTextLayoutManagerDelegate {
909913 if let paragraph = textElement as? NSTextParagraph, ImageFragment.image(paragraph.attributedString) != nil {
910914 return ImageFragment(textElement: textElement, range: range)
911915 }
916 if let paragraph = textElement as? NSTextParagraph, LatexFragment.hasLatex(paragraph.attributedString) {
917 return LatexFragment(textElement: textElement, range: range)
918 }
912919 if let paragraph = textElement as? NSTextParagraph, EntityFragment.hasEntities(paragraph.attributedString) {
913920 return EntityFragment(textElement: textElement, range: range)
914921 }
Sources/OrgPresentation/Display.swift +5 −1
@@ -13,6 +13,8 @@ public struct StartupDisplay: Sendable, Equatable {
1313 public var hideStars: Bool
1414 /// `org-startup-with-inline-images` (`inlineimages`, `noinlineimages`).
1515 public var inlineImages: Bool
16 /// `org-startup-with-latex-preview` (`latexpreview`, `nolatexpreview`).
17 public var latexPreview = false
1618 /// `org-startup-align-all-tables` (`align`, `noalign`).
1719 public var alignTables: Bool
1820 /// `org-startup-truncated`.
@@ -30,7 +32,7 @@ extension Presentation {
3032 }
3133 let wrappers = startupWrappers(tree, hideDrawers: options.hideDrawerStartup, hideBlocks: options.hideBlockStartup)
3234 folds.wrapperFolds = Set(wrappers.map(\.start))
33 return StartupDisplay(
35 var display = StartupDisplay(
3436 folds: folds, wrappers: wrappers,
3537 indented: words.contains("indent") ? true : words.contains("noindent") ? false : options.startupIndented,
3638 hideStars: words.contains("hidestars") ? true : words.contains("showstars") ? false : options.hideLeadingStars,
@@ -38,6 +40,8 @@ extension Presentation {
3840 alignTables: words.contains("align") || (options.startupAlignAllTables && !words.contains("noalign")),
3941 truncated: options.startupTruncated
4042 )
43 display.latexPreview = startupLatexPreview(tree) ?? options.startupWithLatexPreview
44 return display
4145 }
4246
4347 /// 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 {
589589 ("app.clock.default", "Mark as Default Clock Task"), ("app.clock.resolve", "Resolve Open Clocks…"),
590590 ("app.refile", "Refile…"), ("app.refile.copy", "Copy to Refile Target…"), ("app.refile.goto", "Go to Refile Target…"),
591591 ("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"),
593593 ("org.table.toggle-column-width", "Shrink or Expand Table Column"), ("org.table.shrink", "Shrink Table Columns with Widths"),
594594 ("org.table.expand", "Expand Table Columns"),
595595 ("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 {
195195 if !showMarkup, options.prettyEntities { prettify(whole, in: storage, revealed: revealed, scriptExclusions: scriptExclusions) }
196196 applyShrunk(whole, in: storage)
197197 applyImages(whole, in: storage, revealed: revealed)
198 applyLatex(whole, in: storage, revealed: revealed)
198199 storage.endEditing()
199200 }
200201
@@ -235,7 +236,8 @@ extension MobileEditor {
235236
236237 /// Moving to another line shows its markup and hides the last one's.
237238 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 }
239241 let line = caretLine
240242 guard line != revealedLine else { return }
241243 let text = textView.textStorage.string as NSString
Sources/OrgstarMobile/MobileEditor.swift +7 −2
@@ -106,6 +106,8 @@ final class MobileEditor: NSObject, DocumentBuffer {
106106 var revealedLine: NSRange?
107107 /// `org-toggle-inline-images`: lines that are only an image link show the image.
108108 internal(set) var showsImages = false
109 /// `org-latex-preview`: LaTeX fragments show as typeset math.
110 internal(set) var showsLatex = false
109111 /// The view width images were last sized for.
110112 var imageWidth: CGFloat = 0
111113 /// The file's folder, for relative image paths.
@@ -153,6 +155,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
153155 indented = startup.indented
154156 hideStars = startup.hideStars
155157 showsImages = startup.inlineImages
158 showsLatex = startup.latexPreview
156159 shrunk = ShrunkColumns.startup(document.tree)
157160 applyThemeToView()
158161 load(document.text)
@@ -269,6 +272,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
269272 case "org.cycle-global": cycleGlobal()
270273 case "org.link.open": openLinkAtCaret()
271274 case "org.toggle-inline-images": toggleImages()
275 case "org.latex-preview": toggleLatex()
272276 case "editor.toggle-truncate-lines":
273277 truncatesLines.toggle()
274278 onMessage?(truncatesLines ? "Truncate long lines enabled" : "Truncate long lines disabled")
@@ -294,7 +298,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
294298 switch id {
295299 case "org.cycle":
296300 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
298302 case "app.clock.in", "app.clock.out", "app.clock.cancel", "app.clock.goto", "app.clock.in-recent", "app.clock.in-last",
299303 "app.clock.goto-recent", "app.clock.default", "app.clock.resolve", "app.toggle-markup": return onAppCommand != nil
300304 case "app.refile.goto", "app.table-import": return onAppCommand != nil
@@ -549,7 +553,8 @@ extension MobileEditor: NSTextLayoutManagerDelegate {
549553 let string = (textElement as? NSTextParagraph)?.attributedString
550554 let image = string.flatMap(OrgLineFragment.image)
551555 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) }
553558 let fragment = OrgLineFragment(textElement: textElement, range: range)
554559 fragment.folded = folded
555560 fragment.band = band
Sources/OrgstarMobile/MobileFragments.swift +46 −1
@@ -104,6 +104,18 @@ extension NSAttributedString.Key {
104104 static let orgEntityColor = NSAttributedString.Key("OrgEntityColor")
105105 /// The image an image link's line shows under it.
106106 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 }
107119}
108120
109121final class InlineImageBox: NSObject, @unchecked Sendable {
@@ -157,6 +169,35 @@ final class OrgLineFragment: NSTextLayoutFragment, @unchecked Sendable {
157169 return found
158170 }
159171
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
160201 static func hasEntities(_ string: NSAttributedString) -> Bool {
161202 var found = false
162203 string.enumerateAttribute(.orgEntityDisplay, in: NSRange(location: 0, length: string.length)) { value, _, stop in
@@ -182,7 +223,7 @@ final class OrgLineFragment: NSTextLayoutFragment, @unchecked Sendable {
182223 override var renderingSurfaceBounds: CGRect {
183224 var bounds = super.renderingSurfaceBounds
184225 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) }
186227 return bounds
187228 }
188229
@@ -199,6 +240,10 @@ final class OrgLineFragment: NSTextLayoutFragment, @unchecked Sendable {
199240 defer { UIGraphicsPopContext() }
200241 drawEntities(at: point)
201242 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 }
202247 if folded, let line = textLineFragments.first(where: { $0.characterRange.length > 0 }) ?? textLineFragments.first {
203248 let bounds = line.typographicBounds
204249 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
7272
7373To 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.
7474
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
7593** What isn't rendered
7694
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.
7896
7997* Folding
8098
@@ -128,6 +146,7 @@ With no =#+STARTUP= visibility option, a file opens with every heading shown. Dr
128146| =indent=, =noindent= | Indent bodies under headings, or not |
129147| =hidestars=, =showstars= | Hide all stars but the last, or not |
130148| =inlineimages=, =noinlineimages= | Show image links as images, or not |
149| =latexpreview=, =nolatexpreview= | Show LaTeX fragments as typeset math, or not |
131150| =align=, =noalign= | Align every table, or not (=org-startup-align-all-tables=) |
132151| =shrink= | Narrow table columns that have width cookies |
133152
@@ -287,6 +306,7 @@ Wrapping is display only. To rewrap the text of a paragraph, use Org ▸ Fill Pa
287306| Show Markup | View ▸ Show Markup | =⇧⌘M= | off | =show-markup= | every buffer |
288307| Show Line Numbers | View ▸ Show Line Numbers | =⇧⌘L= | on | =display-line-numbers-type= | every buffer |
289308| 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 |
290310| Spell checking | palette | =SPC t s= (Doom) | off | =spell-check= | current buffer |
291311| Truncate long lines | View ▸ Truncate or Wrap Long Lines | =C-x x t= (Emacs), =SPC t w= (Doom) | off | =org-startup-truncated= | current buffer |
292312
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
792792| Narrow to Subtree or Widen (=org.narrow.toggle=) | — | =⌃⌘N= | — | Narrows to the subtree, or widens when already narrowed (=org-toggle-narrow-to-subtree=). |
793793| 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. |
794794| 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=). |
795796
796797** Outline: headings and subtrees
797798
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
146146| =org-hide-leading-stars= | |
147147| =org-startup-align-all-tables= | |
148148| =org-startup-with-inline-images= | |
149| =org-startup-with-latex-preview= | |
149150| =org-cycle-hide-drawer-startup= | |
150151| =org-cycle-hide-block-startup= | |
151152| =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
213214| =spell-check= | boolean | =false= | Check spelling while typing, outside code, links, dates, tags and keywords. |
214215| =electric-pair-mode= | boolean | =true= | Type brackets, =<>= and quotes in pairs. Mirrors =electric-pair-mode=. |
215216| =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=. |
216218| =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=. |
217219| =org-cycle-hide-drawer-startup= | boolean | =true= | Fold drawers when a file opens. =#+STARTUP: hidedrawers= / =nohidedrawers= override it. Mirrors =org-cycle-hide-drawer-startup=. |
218220| =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
446448| =hidestars=, =showstars= | Hide leading stars or show them. |
447449| =align=, =noalign= | Align every table when the file opens, or don't. |
448450| =inlineimages=, =noinlineimages= | Show image links as images, or don't. |
451| =latexpreview=, =nolatexpreview= | Show LaTeX fragments as typeset math, or don't. |
449452| =shrink= | Shrink table columns that have a width cookie. |
450453| =logdone=, =lognotedone=, =nologdone= | Record a time, a note, or nothing when an entry becomes done. |
451454| =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
455458
456459After the startup visibility, orgstar applies each heading's =VISIBILITY= property and folds subtrees tagged =ARCHIVE=, unless =showeverything= is set.
457460
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.
459462
460463** Setup files
461464
@@ -526,7 +529,7 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, =
526529| Emacs variable | Becomes |
527530|--------------------------------------------------------------------+-----------------------------------------------------------------------------------------------|
528531| =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= |
530533| =org-hide-drawer-startup=, =org-hide-block-startup= | =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup= |
531534| =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 |
532535| =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
8383| =org-startup-indented= | Bodies are indented under their headings | =indent=, =noindent= |
8484| =org-hide-leading-stars= | Without indentation, only a heading's last star shows | =hidestars=, =showstars= |
8585| =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= |
8687| =org-startup-align-all-tables= | Every table is aligned | =align=, =noalign= |
8788| =org-startup-truncated= | Long lines run off the right edge, and the editor scrolls sideways | |
8889
@@ -278,9 +279,9 @@ The app icon's badge counts the entries in the agenda's Overdue section that are
278279
279280* Export
280281
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.
282283
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]].
284285
285286* Code blocks and tables
286287
@@ -344,7 +345,7 @@ These settings from =config.toml= apply on iOS:
344345- =org-todo-keywords=, =org-list-allow-alphabetical=
345346- =org-tags-column=, =org-insert-heading-respect-content=, =org-M-RET-may-split-line=, =fill-column=
346347- =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=
348349- =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]=
349350- =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer=
350351- =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.
368369* What the Mac has that iOS doesn't
369370
370371- 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.
372373- Idle detection while a clock runs.
373374- Import from Emacs.
374375- 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:
244244- =C-c C-q= before the first heading (setting file tags) isn't supported.
245245- Priority ranges that aren't letters or numbers are refused.
246246- =#+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]].
248248- =display-line-numbers-type= has no relative or visual mode.
249249- 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.
250250- 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 @@
2828 "version" : "0.25.0"
2929 }
3030 },
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 },
3140 {
3241 "identity" : "tree-sitter",
3342 "kind" : "remoteSourceControl",
scripts/build-app.sh +3
@@ -40,6 +40,9 @@ ditto "$sparkle" "$app/Contents/Frameworks/Sparkle.framework"
4040otool -l "$app/Contents/MacOS/Orgstar" | grep -q '@executable_path/../Frameworks' \
4141 || install_name_tool -add_rpath @executable_path/../Frameworks "$app/Contents/MacOS/Orgstar"
4242
43# SwiftMath's math fonts, which it finds in the app's resources.
44cp -R "$(dirname "$binary")/SwiftMath_SwiftMath.bundle" "$app/Contents/Resources/"
45
4346# Updates: the appcast and its signing key, for signed builds only; a dev build never checks.
4447if [ "$sign" != "-" ]; then
4548 feed_keys=" <key>SUFeedURL</key>