Add forms 2 and 3 of LaTeX fragment.

This commit is contained in:
Tom Alexander 2023-07-18 22:02:38 -04:00
parent c79b8c7833
commit faf81d0143
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -23,7 +23,11 @@ pub fn latex_fragment<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, LatexFragment<'s>> {
let (remaining, _) = alt((parser_with_context!(raw_latex_fragment)(context),))(input)?;
let (remaining, _) = alt((
parser_with_context!(raw_latex_fragment)(context),
parser_with_context!(escaped_parenthesis_fragment)(context),
parser_with_context!(escaped_bracket_fragment)(context),
))(input)?;
let (remaining, _) = space0(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, LatexFragment { source }))
@ -72,3 +76,41 @@ fn brackets<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'
))(input)?;
Ok((remaining, body))
}
#[tracing::instrument(ret, level = "debug")]
fn escaped_parenthesis_fragment<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, &'s str> {
let (remaining, _) = tag("\\(")(input)?;
let (remaining, _) = recognize(many_till(
anychar,
peek(alt((
parser_with_context!(exit_matcher_parser)(context),
tag("\\)"),
))),
))(remaining)?;
let (remaining, _) = tag("\\)")(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, source))
}
#[tracing::instrument(ret, level = "debug")]
fn escaped_bracket_fragment<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, &'s str> {
let (remaining, _) = tag("\\[")(input)?;
let (remaining, _) = recognize(many_till(
anychar,
peek(alt((
parser_with_context!(exit_matcher_parser)(context),
tag("\\]"),
))),
))(remaining)?;
let (remaining, _) = tag("\\]")(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, source))
}