Skip to content

Commit 38d76ed

Browse files
authored
Add LaTeX formatting to doc comments (#118)
There are a few places where a bit of LaTeX would help make things a bit more clear in our documentation. Indeed the C library documentation has several uses of LaTeX which Doxygen handles. This is based on the [rustdoc-katex-demo](https://github.com/paulkernfeld/rustdoc-katex-demo) crate, which demonstates how to include a link to the KaTex code in the HTML generated for the documents.
1 parent 75894cf commit 38d76ed

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

katex-header.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha256-GQlRJzV+1tKf4KY6awAMkTqJ9/GWO3Zd03Fel8mFLnU=" crossorigin="anonymous">
2+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha256-6NiFUFlJ86X0q91d0NU2lr0Tca0m/79PMQ3Nd8jNrok=" crossorigin="anonymous"></script>
3+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha256-u1PrlTOUUxquNv3VNwZcQkTrhUKQGjzpFGAdkyZ1uKw=" crossorigin="anonymous"></script>
4+
<script>
5+
document.addEventListener("DOMContentLoaded", function() {
6+
renderMathInElement(document.body, {
7+
delimiters: [
8+
{left: "$$", right: "$$", display: true},
9+
{left: "\\(", right: "\\)", display: false},
10+
{left: "$", right: "$", display: false},
11+
{left: "\\[", right: "\\]", display: true}
12+
]
13+
});
14+
});
15+
</script>

swiftnav/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ strum = { version = "0.27", features = ["derive"] }
1717

1818
[dev-dependencies]
1919
float_eq = "1.0.1"
20+
21+
# This tells docs.rs to include the katex header for math formatting
22+
# To do this locally
23+
[package.metadata.docs.rs]
24+
rustdoc-args = [ "--html-in-header", "katex-header.html" ]
25+

swiftnav/src/coords.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717
//!
1818
//! --------
1919
//! Conversion from geodetic coordinates latitude, longitude and height
20-
//! (ϕ, λ, h) into Cartesian coordinates (X, Y, Z) can be
20+
//! ($\phi$, $\lambda$, $h$) into Cartesian coordinates ($X$, $Y$, $Z$) can be
2121
//! achieved with the following formulae:
22-
//! * X = (N(ϕ) + h) * cos(ϕ) * cos(λ)
23-
//! * Y = (N(ϕ) + h) * cos(ϕ) * sin(λ)
24-
//! * Z = [(1-e^2) * N(ϕ) + h] * sin(ϕ)
2522
//!
26-
//! Where the 'radius of curvature', N(ϕ), is defined as:
27-
//! * N(ϕ) = a / sqrt(1-e^2 / sin^2(ϕ))
23+
//! $$X = (N(\phi) + h) \cos{\phi}\cos{\lambda}$$
24+
//! $$Y = (N(\phi) + h) \cos{\phi}\sin{\lambda}$$
25+
//! $$Z = \left[(1-e^2)N(\phi) + h\right] \sin{\phi}$$
2826
//!
29-
//! and `a` is the WGS84 semi-major axis and `e` is the WGS84
27+
//! Where the 'radius of curvature', $N(\phi)$, is defined as:
28+
//!
29+
//! $$N(\phi) = \frac{a}{\sqrt{1-e^2\sin^2 \phi}}$$
30+
//!
31+
//! and $a$ is the WGS84 semi-major axis and $e$ is the WGS84
3032
//! eccentricity.
3133
//!
3234
//! --------

swiftnav/src/edc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
/// This CRC is used with the RTCM protocol
1515
///
1616
/// The CRC polynomial used is:
17+
/// $$[
1718
/// x^{24} + x^{23} + x^{18} + x^{17} + x^{14} + x^{11} + x^{10} +
1819
/// x^7 + x^6 + x^5 + x^4 + x^3 + x+1
20+
/// ]$$
1921
///
2022
/// Mask 0x1864CFB, not reversed, not XOR'd
2123
pub fn compute_crc24q(buf: &[u8], initial_value: u32) -> u32 {

swiftnav/src/reference_frame/mod.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,34 @@ pub enum ReferenceFrame {
138138

139139
/// 15-parameter Helmert transformation parameters
140140
///
141-
/// This transformation consists of a 3 dimensional translation,
142-
/// 3 dimensional rotation, and a universal scaling. All terms,
143-
/// except for the reference epoch, have a an additional time
144-
/// dependent term. The rotations are typically very small, so
145-
/// the small angle approximation is used.
141+
/// This is an extension of the 7-parameter Helmert transformation
142+
/// where each term has an additional time-dependent term. This
143+
/// transformation consists of a 3 dimensional translation,
144+
/// 3 dimensional rotation, and a universal scaling. The tranformation
145+
/// takes the form of:
146146
///
147-
/// There are several sign and scale conventions in use with
148-
/// Helmert transformations. In this implementation we follow
149-
/// the IERS conventions, meaning the translations are in
150-
/// millimeters, the rotations are in milliarcseconds, and
151-
/// the scaling is in parts per billion. We also follow the
152-
/// IERS convention for the sign of the rotation terms.
147+
/// $$
148+
/// \begin{bmatrix} X \\\\ Y \\\\ Z \end{bmatrix}\_{REF2} =
149+
/// \begin{bmatrix} X \\\\ Y \\\\ Z \end{bmatrix}\_{REF1} +
150+
/// \begin{bmatrix} \bar{t}_x \\\\ \bar{t}_y \\\\ \bar{t}_z \end{bmatrix} +
151+
/// \begin{bmatrix} \bar{s} & -\bar{r}_z & \bar{r}_y \\\\
152+
/// \bar{r}_z & \bar{s} & -\bar{r}_x \\\\
153+
/// -\bar{r}_y & \bar{r}_x & \bar{s} \end{bmatrix}
154+
/// \begin{bmatrix} X \\\\ Y \\\\ Z \end{bmatrix}\_{REF1}
155+
/// $$
156+
///
157+
/// Where each $\bar{}$ parameter in the transformation is time
158+
/// dependent and is defined to be:
159+
///
160+
/// $$ \bar{p}(t) = p + \dot{p}(t - \tau) $$
161+
///
162+
/// Where $p$ is the constant value, $\dot{p}$ is the rate of
163+
/// change, and $\tau$ is the reference epoch.
164+
///
165+
/// There are several sign conventions in use for the rotation
166+
/// parameters in Helmert transformations. In this implementation
167+
/// we follow the IERS conventions, which is opposite of the original
168+
/// formulation of the Helmert transformation.
153169
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
154170
pub struct TimeDependentHelmertParams {
155171
tx: f64,

0 commit comments

Comments
 (0)