Skip to content

Instantly share code, notes, and snippets.

View durka's full-sized avatar

Alex Burka durka

View GitHub Profile

LaTeX Pearl: Once-expanded Abbreviations

As I get further into my PhD thesis I expect more of these pearls to be about LaTeX. This one came about while I was trying to satisfy a common writing style requirement (one of those rigidly enforced by my advisor): abbreviations and acronyms must be defined once and only once, namely when they are first used.

It's a little hard to remember to do this, and when the editing process involves wholesale reordering of paragraphs and sections, that can require moving the definition to the new first use of an acronym, which is annoying. I'm writing this thesis in separate files per chapter, which are then combined when compiling the whole thesis. So the first use might be in a different file altogether. Furthermore, the chapter files can be compiled individually, so I might want an acronym explained at first use in-chapter in that situation, even if it's omitted when compiling the final thesis.

To implement this, I ended up writing a self-modifying command. That bent m

@durka
durka / cargo test
Last active December 31, 2017 00:27
running 1 test
test src/lib.rs - foo (line 1) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
@durka
durka / -
Created December 14, 2017 19:20
fn main()
{
let archive = Archive::read_and_construct( "./json/trivia.json" );
let question = archive.unwrap().random();
println!("{:?}", question);
}
@durka
durka / -
Created December 12, 2017 21:28
$ LOG_LEVEL=$(python -c "print chr(255)") cargo script xxx.rs
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotUnicode("\xff")
'LOG_LEVEL' not UTF-8 compatible!', src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@durka
durka / -
Created December 12, 2017 21:18
$ LOG_LEVEL=$(cat /dev/random | head -1) cargo script xxx.rs
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotUnicode("\xe1n\x99;\xa2\u{f}\xf6\x8e\u{13}b\'\xdb\u{12}JB\u{16}\u{7f}V~M\xbbaD\xaf6\'\u{1a}BL\xa6\xa0&>\x91xy\x9b\u{6}\xcbor\u{1e}Qg>\xd3\xc7j&\xb8\xdcn\xa4L\u{7}\xdf]\xef")
'LOG_LEVEL' not UTF-8 compatible!', src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@durka
durka / xxx.rs
Created December 12, 2017 21:02
//! ```cargo
//! [dependencies]
//! failure = "*"
//! ```
extern crate failure;
use failure::Error;
use failure::Fail;
use failure::ResultExt;
@durka
durka / -
Created December 12, 2017 21:01
extern crate failure;
use failure::Error;
use failure::Fail;
use failure::ResultExt;
fn logging() -> Result<(), Error> {
let log_level = env::var("LOG_LEVEL")
.unwrap_or_else(|e| match e {
VarError::NotPresent => "".to_owned(),
macro_rules! siaf {
(|$($parm:ident),* $(,)*| $body:expr) => {{
/* ensure no captures */ let closure: fn($($parm: _),*)->_ = |$($parm),*| $body;
(closure)($($parm),*)
}}
}
fn compute_g(a: i32, b: i32, c: i32) -> i32 {
let d = siaf!(|a, b| a + c);
let (e, f) = siaf!(|d| (d - 1, d + 1));
@durka
durka / -
Created November 20, 2017 21:29
ERROR: Error: error in row 221 of crops/20171117: parse error │
Caused by: CSV deserialize error: record 221 (line: 221, byte: 143807): field 35: cannot parse integer from empty string │
Caused by: field 35: cannot parse integer from empty string
@durka
durka / copy.m
Last active November 8, 2017 01:25
save tmp.mat data;
tmp = load('tmp.mat');
data = tmp.data;
clear tmp;
!rm tmp.mat