//! The Texcraft primitive, which returns the word Texcraft as eight separate letter tokens //! //! This primitive is essentially equivalent to `\def\Texcraft{Texcraft}`. //! It was implemented to serve as a simple example of a custom expansion primitive. use texlang::prelude as txl; use texlang::*; /// Get the `\texcraft` expansion primitive. pub fn get_texcraft() -> command::BuiltIn { command::BuiltIn::new_expansion(texcraft_primitive_fn) } pub fn texcraft_primitive_fn( token: token::Token, input: &mut vm::ExpansionInput, ) -> txl::Result<()> { let expansions = input.expansions_mut(); for c in "Texcraft".chars().rev() { expansions.push(token::Token::new_letter(c, token.trace_key())) } Ok(()) } #[cfg(test)] mod tests { use std::collections::HashMap; use super::*; use texlang_testing::State; fn built_in_commands() -> HashMap<&'static str, command::BuiltIn> { HashMap::from([("texcraft", get_texcraft())]) } texlang_testing::test_suite![expansion_equality_tests(( texcraft, r"\texcraft", r"Texcraft" ),),]; }