% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
  12pt,
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={pandoctbl},
  pdfauthor={IAW},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
%%%% preamble.latex by Ivo Welch, May 2019

\usepackage{array}
\newcolumntype{C}{>{\bf}c}
\newcolumntype{R}{>{\bf}r}
\newcolumntype{L}{>{\bf}l}

\providecommand{\mc}{\multicolumn}

\usepackage{xcolor}
\providecommand{\blue}[1]{\textcolor{blue}{#1}}
\providecommand{\red}[1]{\textcolor{red}{#1}}

\usepackage{soul}
\providecommand{\bgyellow}[1]{\hl{#1}}  %% does not really work!

\usepackage{booktabs}

\newcommand{\mes}[1]{\ensuremath{^{\text{\makebox[0pt][l]{#1}}}}}
\providecommand{\tstar}{\mes{***}}
\providecommand{\dstar}{\mes{**}}
\providecommand{\ostar}{\mes{*}}
\providecommand{\nstar}{}

\providecommand{\icaption}[2]{\noindent\caption{#2}\label{tbl:#1}}
\newenvironment{itabular}{\begin{center}\begin{tabular}{*{99}{c}}}{\end{tabular}\end{center}}

\setlength{\tabcolsep}{12pt}
\usepackage{iaw}

%%%% preamble.latex

\title{pandoctbl}
\usepackage{etoolbox}
\makeatletter
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
  \apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother
\subtitle{Personal Preprocessor}
\author{IAW}
\date{May 15, 2019}

\begin{document}
\maketitle

This is an unsupported preprocessing markdown table hack. It adds
\texttt{mdtbl} and \texttt{mdtblio} codeblocks. (An \texttt{mdtblio}
prints the code in a verbatim text area first, before printing it in the
\texttt{mdtbl}.)

An \texttt{mdtbl} has within tablecell alignments based on distances to
left and right separators. Consecutive right separators indicate
multicolumns. The tables can be requested to be smart about numbers
(e.g., negative signs instead of hyphens, proper rounding) within
specific columns. They can be smart about adding stars.

The processor also adds a ``today'' facility. Use `backquote backslash
today backquote'. See this input md file for the following example use:
This file was created on Sun May 19 20:14:35 2019.

The input file for this document is \texttt{pandoctbl.md}.

These table formats have been modestly tested under
\href{https://pandoc.org}{pandoc 2.7} (by John MacFarlane). Because this
preprocessor is primarily for personal use, I can fix bugs as they raise
their heads.

\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}

\clearpage

\hypertarget{setup}{%
\subsection{Setup}\label{setup}}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  Download the
  \href{http://www.ivo-welch.info/computers/pandoctbl}{pandoctbl} perl
  code and this
  \href{http://www.ivo-welch.info/computers/pandoctbl.md}{pandoctbl.md
  sample}
\item
  Install the cpan module
  \href{https://metacpan.org/pod/Perl6::Slurp}{Perl6::Slurp}.
\item
  Run the program:

  \$ pandoctbl pandoctbl.md pandoctbl.html

  \$ pandoctbl pandoctbl.md pandoctbl.tex

  \$ pandoctbl pandoctbl.md pandoctbl.pdf
\item
  Install the preamble files into \textasciitilde/.pandoc/templates:
  \href{preamble.latex.txt}{preamble.latex} and
  \href{preamble.html.txt}{preamble.html} files. These can reflect your
  desired style changes. My own are linked here. You must remove the
  .txt extension, though.
\end{enumerate}

\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}

\clearpage

\hypertarget{feature-cell-alignment}{%
\subsection{Feature: Cell Alignment}\label{feature-cell-alignment}}

\begin{verbatim}
caption: Cell Alignment Example

---t
^ h1-very-left   ^  h1-very-center  ^  h1-very-right ^
---m
| l1             |      c1          |             r3 |
| l1             |      c1          |             r3 |
| l1             |      c1          |             r3 |
---m
^          right ^            right |          right |
^ left           ^ left             | left           |
^     center     ^     center       |     center     |
---b
\end{verbatim}

\begin{table}[!ht]
  \icaption{1}{Cell Alignment Example}
  \begin{itabular}
    

\toprule

  \mc1L{h1-very-left} & \mc1C{h1-very-center} & \mc1R{h1-very-right} \\

\midrule

  \mc1l{l1} &  c1 &\mc1r{r3} \\
  \mc1l{l1} &  c1 &\mc1r{r3} \\
  \mc1l{l1} &  c1 &\mc1r{r3} \\

\midrule

  \mc1R{right} & \mc1r{right} & \mc1r{right} \\
  \mc1L{left} & \mc1l{left} & \mc1l{left} \\
  \mc1C{center} &  center & center \\

\bottomrule

  \end{itabular}
\end{table}

Alignment is determined as follows:

\begin{itemize}
\tightlist
\item
  2 or more spaces at the end and only 1 space at the start:
  left-justified
\item
  2 or more spaces at the start and only 1 space at the end:
  right-justified
\item
  2 or more spaces at the start and 2 or more space at the end: centered
\item
  Fewer start/end spaces --- undefined/ignored.
\end{itemize}

Column header cells can use alignments just like body cells.

\clearpage

\hypertarget{feature-colspans}{%
\subsection{Feature: Colspans}\label{feature-colspans}}

\begin{verbatim}
caption: Multi-Column Spanning Text Example

---t
^ h1-left-3col            ^^^     h1-center-3col      ^^^             h1-right-3col ^^^
---m
|  ctr4  |  ctr5  |  ctr6   |  ctr7  |  ctr8  |  ctr9   |  ctr10  |  ctr11  |  ctr12  |
|     ****ctr4-6*****     |||     ****ctr7-9****      |||      ****ctr10-12****     |||
| lft4   |   --ctr5-6--    ||  rght7 |      ---rght8-9 ||  rght10 | left11-12---    |||
|   ----rght4-6-tres-cols |||  -----rght7-9-tres-cols ||| left10-12-tres-cols---    |||
---b
\end{verbatim}

\begin{table}[!ht]
  \icaption{2}{Multi-Column Spanning Text Example}
  \begin{itabular}
    

\toprule

  \mc3L{h1-left-3col} & \mc3C{h1-center-3col} & \mc3R{h1-right-3col} \\

\midrule

   ctr4 & ctr5 & ctr6 & ctr7 & ctr8 & ctr9 & ctr10 & ctr11 & ctr12 \\
  \mc3c{****ctr4-6*****} & \mc3c{****ctr7-9****} & \mc3c{****ctr10-12****} \\
  \mc1l{lft4} & \mc2c{--ctr5-6--} & \mc1r{rght7} & \mc2r{---rght8-9} & \mc1r{rght10} & \mc3l{left11-12---} \\
  \mc3r{----rght4-6-tres-cols} & \mc3r{-----rght7-9-tres-cols} & \mc3l{left10-12-tres-cols---} \\

\bottomrule

  \end{itabular}
\end{table}

\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}

\clearpage

\hypertarget{feature-cell-content-number-preprocessing}{%
\subsection{Feature: Cell Content Number
Preprocessing}\label{feature-cell-content-number-preprocessing}}

When a table contains a special format line (preceded by \^{}\^{}),
columns with numbers are preprocesed. Negative numbers then receive
proper dashes (and not hyphens). The number of digits to round can be
specified. Cells can have stars with some modicum of attempted
alignment. (In html, this relies on the width of a star being about the
width of one enspace. One issue may be that numbers are now not always
fully right justified---but all such numbers are equally shifted left
just a little to make space for alignment. LaTeX has no such issues,
because it knows about zero-width boxes. There may be a way to coax
html+css into zero-width boxes, too, but I have not investigated this.)

\begin{verbatim}
caption: Numeric Processing Example

---t
^                 ^                *Roots*                             ^^^^
^ From X          ^  squaron  ^   cubismo    ^   teterony   ^      not    ^
---m
| For 2.0         |  1.41421 |   1.25992     |   1.189207   |     -1.1487 |
| For 3.0         |  1.73205 |   1.44224*    |   1.316074   |     1.24573 | 
| For 4.0         |        2 |   1.58740**   |   1.414213   |    -1.31607 |
| For 5.0         |    -2.23 |   1.70997***  |   1.495348   |         0.0 |
---m
| left            |    right |  ----both are centered----   ||      right |
---b
^^                ^  bgyellow 1  ^  blue 2   ^      3       ^     cond 4  ^
---b
\end{verbatim}

\begin{table}[!ht]
  \icaption{3}{Numeric Processing Example}
  \begin{itabular}
    

\toprule

  \mc1C{} & \mc4C{*Roots*} \\
  \mc1L{From X} & \mc1C{squaron} & \mc1C{cubismo} & \mc1C{teterony} & \mc1C{not} \\

\midrule

  \mc1l{For 2.0} & \mc1r{\bgyellow{1.4\nstar}} &  \blue{1.26\nstar} & 1.189 &\mc1r{\red{--1.1487\nstar}} \\
  \mc1l{For 3.0} & \mc1r{\bgyellow{1.7\nstar}} &  \blue{1.44\ostar} & 1.316 &\mc1r{\blue{1.2457\nstar}} \\
  \mc1l{For 4.0} & \mc1r{\bgyellow{2.0\nstar}} &  \blue{1.59\dstar} & 1.414 &\mc1r{\red{--1.3161\nstar}} \\
  \mc1l{For 5.0} & \mc1r{\bgyellow{--2.2\nstar}} &  \blue{1.71\tstar} & 1.495 &\mc1r{\black{0.0000\nstar}} \\

\midrule

  \mc1l{left} & \mc1r{right} & \mc2c{----both are centered----} & \mc1r{right} \\

\bottomrule

  \end{itabular}
\end{table}

A format string, applied \emph{only} to numbers in cells (strings are
ignored), can be attached by starting a line with two carets (\^{}\^{}).
A standalone number in the field is interpreted as digits after the
decimal point. A string of at least two characters is interpreted as
css. The ``cond'' string has special meaning: It attaches ``blue'' to
positives, ``red'' to negatives, and "black to zero.

\begin{itemize}
\tightlist
\item
  column 2: bgyellow, one digits.
\item
  column 3: blue, two digits.
\item
  column 4: three digits.
\item
  column 5: conditional (pos=blue,neg=red,zero=black), four digit.
\end{itemize}

There is one bug: the second trailing `---b' is ignored, presumably
because of the preceding format line.

\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}

\clearpage

\hypertarget{notes}{%
\subsection{Notes}\label{notes}}

\hypertarget{good-abuse}{%
\subsubsection{Good Abuse}\label{good-abuse}}

\begin{itemize}
\item
  The table format can be abused, which makes it even more flexible.

  \begin{itemize}
  \item
    You can abuse the left/center/right spacing to format individual
    cells in individual ways. Just redefine the latex macro and the html
    css. For example, you could define \texttt{cellr} not only to
    text-justify right, but also to italicize and overstrike and this
    would apply only in those cells that start with at least two spaces
    and end with exactly one space.
  \item
    You could define a column style of `overstrike' and have every
    number in such columns be overstruck via css.
  \end{itemize}
\end{itemize}

\hypertarget{missing}{%
\subsubsection{Missing}\label{missing}}

\begin{itemize}
\item
  Horizontal rules in tables:

  \begin{itemize}
  \item
    There is no support for clines. The obvious markdown code equivalent
    would be \texttt{-\/-\/-2-4} in a table. The problem is deciding how
    many dashes should be added in html for such cases.
  \item
    In html output, the table rules are simply replaced by emdashes
    according to the largest entry in all cells in this column. There is
    no intelligent colspan merging.
  \item
    latex tables increase tabcolsep from the default 6pt to 12pt.
  \end{itemize}
\item
  We want a tabular realignment utility (to improve readability, either
  of md inputs or tex/html output)
\item
  I am uncertain whether tabs should be expanded into spaces first.
\item
  A csv table input format
\item
  LaTeX tables could be more intelligent in terms of nice output
  formatting. This would make them more suitable for input into latex.
\item
  HTML output tables do not know about thead and tbody. LaTeX table
  output is not nice-optimized.
\end{itemize}

\hypertarget{bugs}{%
\subsubsection{Bugs}\label{bugs}}

\begin{itemize}
\tightlist
\item
  Bottomrule bug above
\end{itemize}

\end{document}
