Skip to content

Commit 785bdfd

Browse files
committed
Update documentation comments.
1 parent a8da160 commit 785bdfd

File tree

4 files changed

+90
-49
lines changed

4 files changed

+90
-49
lines changed

Sources/LaTeXSwiftUI/Extensions/EnvironmentValues+Extensions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,25 @@ extension EnvironmentValues {
104104
set { self[TeXInputProcessorOptionsKey.self] = newValue }
105105
}
106106

107+
/// The processEscapes value of this environment.
107108
var processEscapes: Bool {
108109
get { self[ProcessEscapesKey.self] }
109110
set { self[ProcessEscapesKey.self] = newValue }
110111
}
111112

113+
/// The equation number mode of this environment.
112114
var equationNumberMode: LaTeX.EquationNumberMode {
113115
get { self[EquationNumberModeKey.self] }
114116
set { self[EquationNumberModeKey.self] = newValue }
115117
}
116118

119+
/// The equation starting number of this environment.
117120
var equationNumberStart: Int {
118121
get { self[EquationNumberStartKey.self] }
119122
set { self[EquationNumberStartKey.self] = newValue }
120123
}
121124

125+
/// The equation number offset of this environment.
122126
var equationNumberOffset: CGFloat {
123127
get { self[EquationNumberOffsetKey.self] }
124128
set { self[EquationNumberOffsetKey.self] = newValue }

Sources/LaTeXSwiftUI/Extensions/View+Extensions.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,52 @@ public extension View {
8080
/// render images in its view.
8181
@available(*, deprecated, message: """
8282
This method will be unavailable in the next version. Use the `processEscapes`,
83-
`equationTags`, `equationTagSide`, and `equationTagIndent` methods instead.
83+
`equationNumberMode`, `equationNumberStart`, and `equationNumberOffset` methods
84+
instead.
8485
""")
8586
func texOptions(_ options: TeXInputProcessorOptions) -> some View {
8687
environment(\.texOptions, options)
8788
}
8889

90+
/// When set to `true`, you may use `\$` to represent a literal dollar sign,
91+
/// rather than using it as a math delimiter, and `\\` to represent a literal
92+
/// backslash (so that you can use `\\\$` to get a literal `\$` or `\\$...$`
93+
/// to get a backslash just before in-line math).
94+
///
95+
/// When `false`, `\$` will not be altered, and its dollar sign may be
96+
/// considered part of a math delimiter. Typically this is set to `true` if
97+
/// you enable the `$ ... $` in-line delimiters, so you can type `\$` and
98+
/// MathJax will convert it to a regular dollar sign in the rendered document.
99+
///
100+
/// - Reference: [Option Descriptions](https://docs.mathjax.org/en/latest/options/input/tex.html#option-descriptions)
101+
///
102+
/// - Parameter process: Whether escapes should be processed.
103+
/// - Returns: A view that processes escapes in its text input.
89104
func processEscapes(_ process: Bool = true) -> some View {
90105
environment(\.processEscapes, process)
91106
}
92107

108+
/// Sets whether block view equation numbers should be hidden, displayed on
109+
/// the left side of an equation, or displayed on the right side.
110+
///
111+
/// - Parameter mode: The equation number mode.
112+
/// - Returns: A view that numbers its equations.
93113
func equationNumberMode(_ mode: LaTeX.EquationNumberMode) -> some View {
94114
environment(\.equationNumberMode, mode)
95115
}
96116

117+
/// Sets the starting value for equation numbers in this view.
118+
///
119+
/// - Parameter value: The starting value.
120+
/// - Returns: A view that numbers its equations.
97121
func equationNumberStart(_ value: Int) -> some View {
98122
environment(\.equationNumberStart, value)
99123
}
100124

125+
/// Sets the number's left or right offset.
126+
///
127+
/// - Parameter offset: The offset to set.
128+
/// - Returns: A view that numbers its equations.
101129
func equationNumberOffset(_ offset: CGFloat) -> some View {
102130
environment(\.equationNumberOffset, offset)
103131
}

Sources/LaTeXSwiftUI/LaTeX.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import MathJaxSwift
2828
import Nuke
2929
import SwiftUI
3030

31+
/// A view that can parse and render TeX and LaTeX equations that contain
32+
/// math-mode marcos.
3133
public struct LaTeX: View {
3234

3335
// MARK: Types
@@ -109,9 +111,16 @@ public struct LaTeX: View {
109111
/// The TeX options to pass to MathJax.
110112
@Environment(\.texOptions) private var texOptions
111113

114+
/// Whether the view should process escapes.
112115
@Environment(\.processEscapes) private var processEscapes
116+
117+
/// The view's equation number mode.
113118
@Environment(\.equationNumberMode) private var equationNumberMode
119+
120+
/// The view's equation starting number.
114121
@Environment(\.equationNumberStart) private var equationNumberStart
122+
123+
/// The view's equation number's offset.
115124
@Environment(\.equationNumberOffset) private var equationNumberOffset
116125

117126
/// The view's current display scale.
@@ -408,24 +417,6 @@ struct LaTeX_Previews: PreviewProvider {
408417
}
409418
.fontDesign(.serif)
410419
.previewLayout(.sizeThatFits)
411-
412-
VStack {
413-
414-
// Don't number block equations (default)
415-
LaTeX("$$a + b = c$$")
416-
.equationNumberMode(.none)
417-
418-
// Add left numbers and a leading offset
419-
LaTeX("$$d + e = f$$")
420-
.equationNumberMode(.left)
421-
.equationNumberOffset(10)
422-
423-
// Add right numbers, a leading offset, and start at 2
424-
LaTeX("$$h + i = j$$ $$k + l = m$$")
425-
.equationNumberMode(.right)
426-
.equationNumberStart(2)
427-
.equationNumberOffset(20)
428-
}
429420
}
430421

431422
}

Sources/LaTeXSwiftUI/Views/EquationNumber.swift

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,71 @@
2525

2626
import SwiftUI
2727

28+
/// A view that draws a number next to an equation.
2829
struct EquationNumber: View {
2930

31+
// MARK: Types
32+
33+
/// The side of the equation that the number appears on.
3034
enum EquationSide {
3135
case left
3236
case right
3337
}
3438

39+
// MARK: Public properties
40+
41+
/// The index of the block attached to this number.
3542
let blockIndex: Int
43+
44+
/// The side of the equation that this number appears on.
3645
let side: EquationSide
3746

47+
// MARK: Private properties
48+
49+
/// The view's equation number mode.
3850
@Environment(\.equationNumberMode) private var equationNumberMode
51+
52+
/// The view's equation starting number.
3953
@Environment(\.equationNumberStart) private var equationNumberStart
54+
55+
/// The view's equation number's offset.
4056
@Environment(\.equationNumberOffset) private var equationNumberOffset
4157

42-
var body: some View {
43-
switch equationNumberMode {
44-
case .left:
45-
if side == .left {
46-
Text("(\(equationNumberStart + blockIndex))")
47-
.padding([.leading], equationNumberOffset)
48-
}
49-
else {
50-
Text("(\(equationNumberStart + blockIndex))")
51-
.padding([.leading], equationNumberOffset)
52-
.foregroundColor(.clear)
53-
}
54-
Spacer(minLength: 0)
55-
case .right:
56-
Spacer(minLength: 0)
57-
if side == .right {
58-
Text("(\(equationNumberStart + blockIndex))")
59-
.padding([.trailing], equationNumberOffset)
60-
}
61-
else {
62-
Text("(\(equationNumberStart + blockIndex))")
63-
.padding([.trailing], equationNumberOffset)
64-
.foregroundColor(.clear)
65-
}
66-
default:
67-
EmptyView()
58+
// MARK: View body
59+
60+
var body: some View {
61+
switch equationNumberMode {
62+
case .left:
63+
if side == .left {
64+
Text("(\(equationNumberStart + blockIndex))")
65+
.padding([.leading], equationNumberOffset)
6866
}
67+
else {
68+
Text("(\(equationNumberStart + blockIndex))")
69+
.padding([.leading], equationNumberOffset)
70+
.foregroundColor(.clear)
71+
}
72+
Spacer(minLength: 0)
73+
case .right:
74+
Spacer(minLength: 0)
75+
if side == .right {
76+
Text("(\(equationNumberStart + blockIndex))")
77+
.padding([.trailing], equationNumberOffset)
78+
}
79+
else {
80+
Text("(\(equationNumberStart + blockIndex))")
81+
.padding([.trailing], equationNumberOffset)
82+
.foregroundColor(.clear)
83+
}
84+
default:
85+
EmptyView()
6986
}
87+
}
7088
}
7189

7290
struct EquationNumber_Previews: PreviewProvider {
73-
static var previews: some View {
74-
EquationNumber(blockIndex: 0, side: .left)
75-
.environment(\.equationNumberMode, .left)
76-
}
91+
static var previews: some View {
92+
EquationNumber(blockIndex: 0, side: .left)
93+
.environment(\.equationNumberMode, .left)
94+
}
7795
}

0 commit comments

Comments
 (0)