Skip to content

Instantly share code, notes, and snippets.

@alexklapheke
Last active April 14, 2023 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexklapheke/0205ae634f5834bf7d97 to your computer and use it in GitHub Desktop.
Save alexklapheke/0205ae634f5834bf7d97 to your computer and use it in GitHub Desktop.
Some useful commands for syntax & semantics
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% %
% Some useful commands for syntax & semantics %
% Author: Alex Klapheke (github/klapheke) %
% Updated: 26 Feb 2017 %
% Licence: GPL v2 %
% Installation: %
% 1. Place in ~/texmf/tex/latex/ %
% 2. $ texhash %
% %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Rule of thumb for formulae:
% Variables should be set in italics
% Constants, functions, and syncategoremata should be set in roman
% e.g., λ, ι, vP, Merge α, lift/lower
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{synsemtools}[2017/02/26 Misc.\ syntax/semantics tools]
\RequirePackage{calc}
\RequirePackage{tikz}
\RequirePackage[leqno,fleqn]{amsmath}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Citations %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Typical, LI-style citations
\RequirePackage[round,sort&compress]{natbib}
\bibpunct[:]{(}{)}{;}{}{}{,}
% Commonly-used abbreviations, as proper citation commands.
% Abbreviations of book titles should be italicized.
% Can also define easy-to-type commands for these, e.g.,
% \newcommand*\ptq{\citetalias{montague1973proper}}
\defcitealias{wittgenstein1953philosophical}{\textit{PI}} % Wittgenstein (1953) Philosophical Investigations, 2nd ed.
\defcitealias{chomsky1957syntactic}{\textit{SS}} % Chomsky (1957) Syntactic Structures
\defcitealias{chomsky1965aspects}{\textit{Aspects}} % Chomsky (1965) Aspects of the Theory of Syntax
\defcitealias{chomsky1968sound}{\textit{SPE}} % Chomsky & Halle (1968) The Sound Pattern of English
\defcitealias{lewis1970general}{GS} % Lewis (1970) General Semantics
\defcitealias{montague1973the}{PTQ} % Montague (1973) The proper treatment of quantification in ordinary English
\defcitealias{karttunen1979conventional}{K\&P} % Kartunnen & Peters (1979) Conventional Implicature
\defcitealias{heim1998semantics}{H\&K} % Heim & Kratzer (1998) Semantics in Generative Grammar
\defcitealias{kratzer2002indeterminate}{K\&S} % Kratzer & Shimoyama (2002) Indeterminate Pronouns: The View from Japanese
\defcitealias{hauser2002faculty}{HCF} % Hauser, Chomsky, & Fitch (2002) The Faculty of Language
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Numbered examples %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Various linguistics tools, including example numbering.
% Modified to exclude ^ and _ shortcuts (which are not
% worth the havoc they wreak on other packages; see
% <http://www.essex.ac.uk/linguistics/external/clmt/latex4ling/examples/>)
\RequirePackage{gb4e+}
\let\eachwordone=\it % Italicize original in glosses
\let\c@exx\c@equation % Use equation numbering for gb4e examples, for consistency
% Simple example references to gb4e:
% \cref{ex:colorlessgreen} -> example (1)
% Should be called AFTER hyperref!
\RequirePackage[sort&compress]{cleveref}
% tell cleveref to use the word "example" to refer to examples,
% and to put example numbers in brackets
\crefname{xnumi}{example}{examples}
\creflabelformat{xnumi}{(#2#1#3)}
\crefname{xnumii}{example}{examples}
\creflabelformat{xnumii}{(#2#1#3)}
\crefname{xnumiii}{example}{examples}
\creflabelformat{xnumiii}{(#2#1#3)}
\crefname{xnumiv}{example}{examples}
\creflabelformat{xnumiv}{(#2#1#3)}
% For "stacks" of options in braces. Takes optional alignment argument:
% John \optstack[l]{knows \\ ? cares \\ * doubts} who came to the party.
% ⎧ knows ⎫
% => John ⎨ ? cares ⎬ who came to the party.
% ⎩ * doubts ⎭
\newcommand*\optstack[2][l]{\ensuremath{\left\{\begin{tabular}{@{}#1@{}}#2\end{tabular}\right\}}}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% General Definitions %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Superscript on the left <http://tex.stackexchange.com/a/52080>
\def\presuper#1#2{\mathop{}\mathopen{\vphantom{#2}}^{#1}\kern-\scriptspace#2}
% Properly-spaced dot for lambda-like expressions; a bare period
% character will have the (very tight) spacing of a decimal point.
\def\l@mbdadot[#1]{#1\mathrel{.}}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Math/Logic %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% miscellaneous symbols:
\let\emptyset\varnothing % the latter is much nicer (requires amssymb)
\newcommand*\zfc{\textsf{ZFC}}
% nicer syntactic inference <http://tex.stackexchange.com/a/222510>
\DeclareRobustCommand\turnstile{\bigspace{\mathrel{|}\joinrel\mkern-.5mu\mathrel{-}}}
% set theory
% \DeclareMathOperator{\powerset}{\mathcal{P}} % \wp is dispreferred for this
% lattice theory
\DeclareMathOperator{\filter}{\uparrow} % alternative: \newcommand\filter[1]{\presuper{f}{#1}}
\DeclareMathOperator{\ideal}{\downarrow} % alternative: \newcommand\ideal[1]{\presuper{i}{#1}}
% define := symbol in math mode <http://tex.stackexchange.com/a/4881>
\newcommand*\defeq{\mathrel{\vcenter{\baselineskip0.5ex \lineskiplimit0pt
\hbox{\scriptsize.}\hbox{\scriptsize.}}}=}
% For logical operators that connect formulas with relations like '='
% in them, that should have more space than the relations. Example:
% \forall x,y \lbrack x=y \bigor x\ne y \rbrack
\newcommand*\bigmathskip{\mskip 6mu plus 5mu\relax}
\newcommand*\bigspace[1]{\bigmathskip#1\bigmathskip}
\newcommand*\bigand{\bigspace{\land}}
\newcommand*\bigor{\bigspace{\lor}}
\newcommand*\bigarrow{\bigspace{\rightarrow}}
\newcommand*\bigArrow{\bigspace{\Rightarrow}}
% Hilbert's epsilon operator or Frege's extension operator
\newcommand*\ep{{\mathord{\mathrm{\epsilon}}}}
% linear logic operators
\newcommand*\lintens{\mathbin{\otimes}}
\newcommand*\linplus{\mathbin{\oplus}}
\newcommand*\linwith{\mathbin{\&}}
\newcommand*\linpar{\mathbin{\rotatebox[origin=c]{180}{\&}}} % exists at U+214B but most fonts don't have it
\newcommand*\linimpl{\mathbin{\multimap}}
\DeclareMathOperator{\ofcourse}{!}
\DeclareMathOperator{\whynot}{?}
% combinators in the SKI-calculus
\DeclareMathOperator{\CombI}{I}
\DeclareMathOperator{\CombK}{K}
\DeclareMathOperator{\CombS}{S}
% Polish notation
\DeclareMathOperator{\Pnot}{N} % negation
\DeclareMathOperator{\Pand}{K} % conjunction
\DeclareMathOperator{\Por}{A} % disjunction
\DeclareMathOperator{\Pimpl}{C} % implication
\DeclareMathOperator{\Pbiimpl}{E} % biimplication
\DeclareMathOperator{\Pnand}{D} % sheffer stroke
\DeclareMathOperator{\Ptrue}{V} % tautology
\DeclareMathOperator{\Pfalse}{O} % contradiction
\DeclareMathOperator{\Pexists}{\Sigma} % existential quantifier
\DeclareMathOperator{\Pforall}{\Pi} % universal quantifier
\DeclareMathOperator{\Pdiamond}{M} % modal possibility
\DeclareMathOperator{\Pbox}{L} % modal necessity
% Big-O notation
\newcommand*{\BigO}[1]{\operatorname{O}(#1)}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Semantics %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% easy nestable angle brackets: $P_\<e,\<e,t>>$ <https://tex.stackexchange.com/a/214973>
\def\<#1>{\ensuremath{\bgroup\left\langle\ignorespaces#1\unskip\right\rangle\egroup}}
% double brackets for denotations ("Oxford brackets") ⟦...⟧
\newcommand*\den[1]{\ensuremath{\big\llbracket\textnormal{\strut #1}\big\rrbracket}}
% lambda/iota functions with optional dot:
% \lam x -> λx
% \lam[x]x^2 -> λx . x²
\newcommand*\lam{\mathord{\mathrm{\lambda}}\@ifnextchar[{\l@mbdadot}{}}
\newcommand*\io{\mathord{\mathrm{\iota}}\@ifnextchar[{\l@mbdadot}{}}
% type-shifting operations
\DeclareMathOperator{\lift}{lift}
\DeclareMathOperator{\lowr}{lower} % \lower is already defined
\DeclareMathOperator{\ident}{ident}
\DeclareMathOperator{\iot}{iota} % \iota is already defined
\DeclareMathOperator{\BE}{BE} % Partee's (1986) BE operator
\newcommand*\nom[1]{\presuper{\cap}{#1}} % properties -> kinds (Chierchia 1984)
\newcommand*\pred[1]{\presuper{\cup}{#1}} % kinds -> properties (Chierchia 1984)
\newcommand*\up[1]{\presuper{\wedge}{#1}} % abstraction over worlds
\newcommand*\down[1]{\presuper{\vee}{#1}} % application of implicit world argument
% entailment, presupposition, & implicature
\newcommand*\entails{\mathrel{\Rightarrow}}
\newcommand*\presupposes{\mathrel{\gg}}
\newcommand*\implicates{\mathrel{\leadsto}}
% Rooth's (1992) focus operator
\DeclareMathOperator{\focus}{\sim}
% exhaustivity operators and alternative sets
\newcommand*\ALT{\textsc{alt}}
\DeclareMathOperator{\exh}{Exh}
\DeclareMathOperator{\oalt}{O_\ALT}
% assertion and presupposition parts (Chierchia 2013)
\newcommand*\assert[1]{\presuper{\mathrm{\alpha}}{#1}} % assertion part of a partial proposition
\newcommand*\presup[1]{\presuper{\mathrm{\pi}}{#1}} % presupposition part of a partial proposition
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Number & Plurality %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Atomicity
\DeclareMathOperator{\at}{AT}
% From Link (1983). Example:
% \propersum[x]P(x)\defeq\io[x]\ppl{P}(x)\land\forall y\left\lbrack\pl{P}(y)\to y\atomicpart x\right\rbrack
% Predicate modifiers
\newcommand*\pl[1]{\presuper{\ast}{#1}} % plural predicate (*P)
\newcommand*\ppl[1]{\presuper{\circledast}{#1}} % proper plural predicate (⊛P)
\newcommand*\massterm[1]{\presuper{m}{#1}} % mass term correspondent (ᵐP)
% Relations
\newcommand*\atomicpart{\mathrel{\Pi}} % atomic part (Π)
\newcommand*\matpart{\mathrel{\top}} % material part (⊤)
\newcommand*\makesup{\mathrel{\vartriangleright}} % constitues/makes up (▷)
% Maximizers (with dot, as in Landman (1989)). Without a dot, use a thin space:
% \atomicsum[x] P(x) -> σx . Px
% \atomicsum x\,P(x) -> σx Px
\newcommand*\atomicsum{\mathord{\mathrm{\sigma}}\@ifnextchar[{\l@mbdadot}{}} % sum (σxPx)
\newcommand*\propersum{\mathord{\mathrm{\sigma}^\ast}\@ifnextchar[{\l@mbdadot}{}} % proper sum (σ*xPx)
\newcommand*\matfusion{\mathord{\mathrm{\mu}}\@ifnextchar[{\l@mbdadot}{}} % material fusion (μxPx)
% From Schwarzschild (2009). Defined at U+229C but most fonts don't have it.
% This definition ensures the operator will have the same dimensions and
% spacing as a normal equals sign. These values should work with most math fonts.
\newlength{\eqwd}\setlength{\eqwd}{\widthof{$=$}}
\newcommand*\sharepartic{\mathrel{\ooalign{$=$\cr\hidewidth\lower0.05ex\hbox{%
\tikz{\draw[outer sep=0pt,inner sep=0pt] (0,0) circle (0.44\eqwd);}}\hidewidth}}}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Temporal & Modal Logic %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% accessibility relation
\newcommand*\acc{\mathrel{\mathrm{R}}}
% modal quantifiers
\DeclareMathOperator{\nec}{\Box}
\DeclareMathOperator{\pos}{\Diamond}
% from Anscombe (1964)
\newcommand*\andthen{\mkern6mu\mathcal{T}\mkern1mu}
% from Parsons (1990)
\DeclareMathOperator{\cul}{Cul}
\DeclareMathOperator{\hold}{Hold}
% tau operator in event semantics
\DeclareMathOperator{\timeof}{\mathrm{\tau}}
% temporal logic operators
\DeclareMathOperator{\TemP}{P} % past
\DeclareMathOperator{\TemF}{F} % future
\DeclareMathOperator{\TemH}{H} % has been
\DeclareMathOperator{\TemG}{G} % going to be
\DeclareMathOperator{\TemM}{M} % temporal possibility
\DeclareMathOperator{\TemN}{N} % temporal necessity
\DeclareMathOperator{\TemS}{S} % since
\DeclareMathOperator{\TemU}{U} % until
% Timelines (kind of crappy):
% \begin{timeline}{4}
% \timelineevent[event 1]{-1}{0}
% \timelineevent[event 2]{2}{3}
% \end{timeline}
\newenvironment{timeline}[1]{%
\begin{tikzpicture}[thick]%
\draw[->]%
(-#1-1,0) -- (#1+1,0) node[below right] {t};%
\foreach \x in {-#1,...,#1}%
\draw (\x,0) -- ++(0,-5pt) node[below] {\footnotesize$t_{\x}$};%
}{\end{tikzpicture}}
\newcommand\timelineevent[3][]{
\draw[fill=lightgray] (#2,0) rectangle node[above] {\strut #1} (#3,0.25);%
}
% Bhatt & Pancheva (2005)-style viewpoint aspect diagrams:
% Simple \viewpoint{-1 }{ 1 }{-1 }{ 1 }
% Perfective \viewpoint{-1.5}{ 1.5}{-1 }{ 1 }
% Progressive \viewpoint{-1 }{ 1 }{-1.5}{ 1.5}
% Right edge \viewpoint{ 0 }{ 1.5}{-1.5}{ 1.5}
% Left edge \viewpoint{-1.5}{ 0 }{-1.5}{ 1.5}
% End \viewpoint{ 0 }{ 1.5}{-1.5}{ 1 }
% Beginning \viewpoint{-1.5}{ 0 }{-1 }{ 1.5}
% Anterior \viewpoint{ 0.5}{ 1.5}{-1.5}{-0.5}
% Posterior \viewpoint{-1.5}{-0.5}{ 0.5}{ 1.5}
\newcommand\viewpoint[4]{\mbox{%
\vspace{0pt}\begin{tikzpicture}[thick,baseline]%
\draw[->] (-2,0) -- (2,0) node[below right] {};%
\draw[fill=lightgray] (#1,0) rectangle node[below=0.5ex] {\small R} (#2,-0.25);%
\draw[fill=darkgray] (#3,0) rectangle node[above=0.5ex] {\small E} (#4, 0.25);%
\end{tikzpicture}%
}}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Inquisitive Semantics %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% \begin{tikzpicture}[>=latex,scale=.8]
% \tikzstyle{index gray}=[inner sep=2pt, black, circle, fill=lightgray]
% \tikzstyle{opaque}=[fill=gray,fill opacity=.1]
% \tikzstyle{counter}=[densely dashed]
% % Possibilities
% \draw[opaque,counter,rounded corners] (-1.7,1.7) rectangle (-.2, .2);
% \draw[opaque,rotate=180,rounded corners]
% (-1.7,0) -- (-1.7,1.7) -- (1.7, 1.7) -- (1.7,.7)
% -- (-.7,-1.7) -- (-1.7,-1.7) -- (-1.7,0);
% % Indices
% \draw (-1,1) node[index gray] (yy) {$11$};
% \draw (1,1) node[index gray] (yn) {$10$};
% \draw (-1,-1) node[index gray] (ny) {$01$};
% \draw (1,-1) node[index gray] (nn) {$00$};
% \end{tikzpicture}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Syntax %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% X⁰ (for use in text mode; requires fontspec package and compatible font)
\newcommand*\head{{\addfontfeature{VerticalPosition=Superior}0}}
% Left/right periphery markers that span lines (for glosses):
% {\gll ... \rperiph{VP} ... \\
% ... {} ... \\
% \trans `Gloss'}
\newcommand*\lperiph[1]{\smash{\raisebox{-0.5\baselineskip}{\rm$\biggl[_\textsubscript{#1}$}}}
\newcommand*\rperiph[1]{\smash{\raisebox{-0.5\baselineskip}{\rm$\biggr]_\textsubscript{#1}$}}}
% Subscript indexing:
% Bill\coindex{i} said John\coindex{k} saw himself\coindex{*i/k}.
% These settings should work with most fonts
\newcommand*\coindex[1]{%
{\footnotesize\ensuremath{{}_{\textnormal{\c@index#1\relax\mathstrut}}}}%
}
\def\c@index#1{\ignorespaces%
\ifx#1\relax%
\let\next\relax%
\else\ifx#1*\expandafter{$*$}%
\else\ifx#1?\expandafter{\scalebox{0.75}{?}}%
\else\ifx#1/\expandafter{\kern 0.5pt/\kern 0.3pt}% looser kerning for ease of reading
\else\expandafter{#1}%
\fi\fi\fi
\let\next\c@index%
\fi\next%
}
% forest is much more extensible and better laid-out than [tikz-]qtree
% these settings try to look like qtree defaults
\RequirePackage{forest}
\forestset{tree/.style={for tree={%
align=center,
parent anchor=south,
child anchor=north,
calign=fixed edge angles,
calign primary angle=-67.5,
calign secondary angle=67.5
}}}
% movement: \movel{startnode}{endnode}{1}
\newcommand\movel[3]{\draw[thin,->,out=180,in=270,looseness=#3,shorten >=1pt,shorten <=1pt] (#1.west) to (#2.south);} % leftward movement
\newcommand\mover[3]{\draw[thin,->,out=0, in=270,looseness=#3,shorten >=1pt,shorten <=1pt] (#1.east) to (#2.south);} % rightward movement
% Finite-State Automata:
% \begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=2cm]
% \node[initial,state] (1) {$1$};
% \node[state,accepting] (2) [right of=1] {$2$};
% \path[->] (1) edge [bend right] node[below] {a} (2);
% \path[->] (2) edge [bend right] node[below] {b} (1);
% \path[->] (1) edge [loop below] node[below] {b} (1);
% \path[->] (2) edge [loop below] node[below] {a} (2);
% \end{tikzpicture}
\usetikzlibrary{positioning,arrows,automata}
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% Phonetics/Phonology %
%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%
% This section assumes the use of XeTeX, which allows full UTF-8
% input, and lets you use a real IPA font like Gentium or Junicode.
% Unless you need crazy things like "open o-e ligature", this is
% probably preferable to tipa. See <https://tex.stackexchange.com/a/75>
\RequirePackage{ifxetex}
\ifxetex
% Modifiers (WARNING: Unicode combining marks. Edit with caution)
\newcommand*\tiebar[2]{#1͡#2} % double articulation
\newcommand*\voiced[1]{#1̬}
\newcommand*\voiceless[1]{#1̥}
\newcommand*\syll[1]{#1̩}
\newcommand*\nasal[1]{#1̃}
\newcommand*\retro[1]{#1̣}
\newcommand*\dent[1]{#1̪}
% Various apostrophe-like things
\newcommand*\stress{ˈ}
\newcommand*\ej{ʼ} % ejective
\newcommand*\ayn{ʿ}
\newcommand*\hamza{ʾ}
\newcommand*\okina{ʻ} % proper setting: \newcommand*\hawaii{Hawai\okina{}i}
\fi
% Phonological rules:
% \phonc{z}{s}{\placehold
% \begin{phonfeat}
% \mbox{–syl} \\
% \mbox{-voi}
% \end{phonfeat}
% }
\RequirePackage{phonrule}
% Autosegmental tiers: <http://tex.stackexchange.com/a/240372>
% \begin{forest}syll
% [$\sigma$ [X,tier=tim [$\alpha$ː,name=a ]]
% [X,tier=tim,name=x ]
% ]
% \draw (x.south) -- (a.north);
\forestset{syll/.style={for tree={%
align=center,
parent anchor=south,
child anchor=north,
calign=center,
inner sep=0pt,
where n children=0{tier=seg}{}
}}}
% OT tableaux (from <http://sanders.phonologist.org/OTtablx/>)
% Warning: breaks some font packages like newtxtext
% \usepackage[medium,open,noipa]{OTtablx}
% % Alternative for OT tableaux (calls amssymb which messes with some font packages):
% % \begin{tableau}{c:c|c}
% % \inp{stap} \const{*Complex} \const{Anchor-IO} \const{Contiguity-IO}
% % \cand{stap} \vio{*!} \vio{} \vio{}
% % \cand[\Optimal]{sap} \vio{} \vio{} \vio{*}
% % \cand{tap} \vio{} \vio{*!} \vio{}
% % \end{tableau}
% \usepackage[notipa,shadedcells]{ot-tableau}
% \renewcommand\OptimalMarker{☞}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment