%%%%%%%%% \iffalse meta-comment
%
% Copyright (C) 2018 by Jeffrey B. Arnold <jeffrey.arnold@gmail.com>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Jeffrey B. Arnold.
%
% This work consists of the files lstbayes.dtx and lstbayes.ins
% and the derived filebase lstbayes.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{lstbayes.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{lstbayes}
%<*package>
    [2018/07/06 lstbayes listings language drivers for BUGS, JAGS, and Stan]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{lstbayes}
\usepackage{hyperref}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{lstbayes.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{12}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{2015-09-26}{2015/09/26}{Converted to DTX file}
% \changes{2015-09-27}{2015/09/27}{Fix README}
% \changes{2015-09-28}{2015/09/27}{Fix README. Add keywords for all built-in functions that are in Stan v2.8.0.}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \providecommand*{\url}{\texttt}
% \GetFileInfo{lstbayes.dtx}
% \title{The \textsf{lstbayes} package}
% \author{Jeffrey B. Arnold \\ \url{jeffrey.arnold@gmail.com}}
% \date{\fileversion~from \filedate}
%
% \maketitle
%
% \section{Introduction}
%
% This package provides language drivers for the \href{https://www.ctan.org/tex-archive/macros/latex/contrib/listings/}{\textsf{listings}} package for the several Bayesian modeling languages: BUGS, JAGS, and Stan.
%
% \section{Usage}
%
% % See the documentation of the \textsf{listings} package.
%

%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\RequirePackage{listings}
%    \end{macrocode}
%
% \subsection{BUGS}
%
% Language driver for BUGS, including \href{http://www.openbugs.net/w/FrontPage}{WinBUGS} and \href{http://openbugs.net}{OpenBUGS}.
% The driver is based on \href{http://www.openbugs.net/Manuals/Manual.html}{OpenBUGS v. 3.2.3}.
%
%    \begin{macrocode}
\lstdefinelanguage{BUGS}{
  morekeywords=[1]{for,in,model,T,I,C},%
  morecomment=[l]{\#},%
  sensitive=true,%
  alsoletter={.},%
  otherkeywords={<-,~},%
  literate={<-}{{$\leftarrow$}}1 {~}{{$\sim$}}1%
}
\lstalias[]{OpenBUGS}[]{BUGS}
\lstalias[]{WinBUGS}[]{BUGS}
%    \end{macrocode}
%
% \subsection{JAGS}
%
% Language driver for \href{http://mcmc-jags.sourceforge.net/}{JAGS}.
% The driver is based on JAGS version 3.4.0 (Sept 4, 2013).
%
%
%    \begin{macrocode}
\lstdefinelanguage[]{JAGS}[]{BUGS}{
  morekeywords=[1]{data,var,const},%
  morecomment=[n]{/*}{*/}%
}
%    \end{macrocode}
%
% \subsection{Stan}
%
% Language driver for \href{http://mc-stan.org/}{Stan}.
% The driver is based on Stan modeling language version \href{https://github.com/stan-dev/stan/releases/download/v2.17.0/stan-reference-2.17.0.pdf}{2.17.0}.
%
%    \begin{macrocode}
\lstdefinelanguage{Stan}{
  morekeywords=[1]{%
    functions,%
    data,%
    else,%
    for,%
    generated,%
    if,%
    in,%
    increment_log_prob,%
    integrate_ode_bdf,%
    integrate_ode_rk45,%
    integrate_ode,%
    lower,%
    model,%
    parameters,%
    print,%
    quantities,%
    reject,%
    return,%
    T,%
    target,%
    transformed,%
    upper,%
    while%
  },%
  morekeywords=[2]{%
    cholesky_factor_corr,%
    cholesky_factor_cov,%
    corr_matrix,%
    cov_matrix,%
    int,%
    matrix,%
    ordered,%
    positive_ordered,%
    real,%
    row_vector,%
    simplex,%
    unit_vector,%
    vector,%
    void%
  },%
  morekeywords=[3]{%
    Phi,%
    Phi_approx,%
    abs,%
    acos,%
    acosh,%
    algebra_solver,%
    append_array,%
    append_col,%
    append_row,%
    asin,%
    asinh,%
    atan,%
    atan2,%
    atanh,%
    bernoulli,%
    bernoulli_cdf,%
    bernoulli_lccdf,%
    bernoulli_lcdf,%
    bernoulli_logit,%
    bernoulli_logit_lpmf,%
    bernoulli_logit_rng,%
    bernoulli_lpmf,%
    bernoulli_rng,%
    bessel_first_kind,%
    bessel_second_kind,%
    beta,%
    beta_binomial,%
    beta_binomial_cdf,%
    beta_binomial_lccdf,%
    beta_binomial_lcdf,%
    beta_binomial_lpmf,%
    beta_binomial_rng,%
    beta_cdf,%
    beta_lccdf,%
    beta_lcdf,%
    beta_lpdf,%
    beta_rng,%
    binary_log_loss,%
    binomial,%
    binomial_cdf,%
    binomial_coefficient_log,%
    binomial_lccdf,%
    binomial_lcdf,%
    binomial_logit,%
    binomial_logit_lpmf,%
    binomial_lpmf,%
    binomial_rng,%
    block,%
    categorical,%
    categorical_logit,%
    categorical_logit_lpmf,%
    categorical_logit_rng,%
    categorical_lpmf,%
    categorical_rng,%
    cauchy,%
    cauchy_cdf,%
    cauchy_lccdf,%
    cauchy_lcdf,%
    cauchy_lpdf,%
    cauchy_rng,%
    cbrt,%
    ceil,%
    chi_square,%
    chi_square_cdf,%
    chi_square_lccdf,%
    chi_square_lcdf,%
    chi_square_lpdf,%
    chi_square_rng,%
    cholesky_decompose,%
    choose,%
    col,%
    cols,%
    columns_dot_product,%
    columns_dot_self,%
    cos,%
    cosh,%
    cov_exp_quad,%
    crossprod,%
    csr_extract_u,%
    csr_extract_v,%
    csr_extract_w,%
    csr_matrix_times_vector,%
    csr_to_dense_matrix,%
    cumulative_sum,%
    determinant,%
    diag_matrix,%
    diag_post_multiply,%
    diag_pre_multiply,%
    diagonal,%
    digamma,%
    dims,%
    dirichlet,%
    dirichlet_lpdf,%
    dirichlet_rng,%
    distance,%
    dot_product,%
    dot_self,%
    double_exponential,%
    double_exponential_cdf,%
    double_exponential_lccdf,%
    double_exponential_lcdf,%
    double_exponential_lpdf,%
    double_exponential_rng,%
    e,%
    eigenvalues_sym,%
    eigenvectors_sym,%
    erf,%
    erfc,%
    exp,%
    exp2,%
    exp_mod_normal,%
    exp_mod_normal_cdf,%
    exp_mod_normal_lccdf,%
    exp_mod_normal_lcdf,%
    exp_mod_normal_lpdf,%
    exp_mod_normal_rng,%
    expm1,%
    exponential,%
    exponential_cdf,%
    exponential_lccdf,%
    exponential_lcdf,%
    exponential_lpdf,%
    exponential_rng,%
    fabs,%
    falling_factorial,%
    fdim,%
    floor,%
    fma,%
    fmax,%
    fmin,%
    fmod,%
    frechet,%
    frechet_cdf,%
    frechet_lccdf,%
    frechet_lcdf,%
    frechet_lpdf,%
    frechet_rng,%
    gamma,%
    gamma_cdf,%
    gamma_lccdf,%
    gamma_lcdf,%
    gamma_lpdf,%
    gamma_p,%
    gamma_q,%
    gamma_rng,%
    gaussian_dlm_obs,%
    gaussian_dlm_obs_lpdf,%
    get_lp,%
    gumbel,%
    gumbel_cdf,%
    gumbel_lccdf,%
    gumbel_lcdf,%
    gumbel_lpdf,%
    gumbel_rng,%
    head,%
    hypergeometric,%
    hypergeometric_lpmf,%
    hypergeometric_rng,%
    hypot,%
    inc_beta,%
    int_step,%
    integrate_ode,%
    integrate_ode_bdf,%
    integrate_ode_rk45,%
    inv,%
    inv_Phi,%
    inv_chi_square,%
    inv_chi_square_cdf,%
    inv_chi_square_lccdf,%
    inv_chi_square_lcdf,%
    inv_chi_square_lpdf,%
    inv_chi_square_rng,%
    inv_cloglog,%
    inv_gamma,%
    inv_gamma_cdf,%
    inv_gamma_lccdf,%
    inv_gamma_lcdf,%
    inv_gamma_lpdf,%
    inv_gamma_rng,%
    inv_logit,%
    inv_sqrt,%
    inv_square,%
    inv_wishart,%
    inv_wishart_lpdf,%
    inv_wishart_rng,%
    inverse,%
    inverse_spd,%
    is_inf,%
    is_nan,%
    lbeta,%
    lchoose,%
    lgamma,%
    lkj_corr,%
    lkj_corr_cholesky,%
    lkj_corr_cholesky_lpdf,%
    lkj_corr_cholesky_rng,%
    lkj_corr_lpdf,%
    lkj_corr_rng,%
    lmgamma,%
    lmultiply,%
    log,%
    log10,%
    log1m,%
    log1m_exp,%
    log1m_inv_logit,%
    log1p,%
    log1p_exp,%
    log2,%
    log_determinant,%
    log_diff_exp,%
    log_falling_factorial,%
    log_inv_logit,%
    log_mix,%
    log_rising_factorial,%
    log_softmax,%
    log_sum_exp,%
    logistic,%
    logistic_cdf,%
    logistic_lccdf,%
    logistic_lcdf,%
    logistic_lpdf,%
    logistic_rng,%
    logit,%
    lognormal,%
    lognormal_cdf,%
    lognormal_lccdf,%
    lognormal_lcdf,%
    lognormal_lpdf,%
    lognormal_rng,%
    machine_precision,%
    matrix_exp,%
    max,%
    mdivide_left_spd,%
    mdivide_left_tri_low,%
    mdivide_right_spd,%
    mdivide_right_tri_low,%
    mean,%
    min,%
    modified_bessel_first_kind,%
    modified_bessel_second_kind,%
    multi_gp,%
    multi_gp_cholesky,%
    multi_gp_cholesky_lpdf,%
    multi_gp_lpdf,%
    multi_normal,%
    multi_normal_cholesky,%
    multi_normal_cholesky_lpdf,%
    multi_normal_cholesky_rng,%
    multi_normal_lpdf,%
    multi_normal_prec,%
    multi_normal_prec_lpdf,%
    multi_normal_rng,%
    multi_student_t,%
    multi_student_t_lpdf,%
    multi_student_t_rng,%
    multinomial,%
    multinomial_lpmf,%
    multinomial_rng,%
    multiply_log,%
    multiply_lower_tri_self_transpose,%
    neg_binomial,%
    neg_binomial_2,%
    neg_binomial_2_cdf,%
    neg_binomial_2_lccdf,%
    neg_binomial_2_lcdf,%
    neg_binomial_2_log,%
    neg_binomial_2_log_lpmf,%
    neg_binomial_2_log_rng,%
    neg_binomial_2_lpmf,%
    neg_binomial_2_rng,%
    neg_binomial_cdf,%
    neg_binomial_lccdf,%
    neg_binomial_lcdf,%
    neg_binomial_lpmf,%
    neg_binomial_rng,%
    negative_infinity,%
    normal,%
    normal_cdf,%
    normal_lccdf,%
    normal_lcdf,%
    normal_lpdf,%
    normal_rng,%
    not_a_number,%
    num_elements,%
    ordered_logistic,%
    ordered_logistic_lpmf,%
    ordered_logistic_rng,%
    owens_t,%
    pareto,%
    pareto_cdf,%
    pareto_lccdf,%
    pareto_lcdf,%
    pareto_lpdf,%
    pareto_rng,%
    pareto_type_2,%
    pareto_type_2_cdf,%
    pareto_type_2_lccdf,%
    pareto_type_2_lcdf,%
    pareto_type_2_lpdf,%
    pareto_type_2_rng,%
    pi,%
    poisson,%
    poisson_cdf,%
    poisson_lccdf,%
    poisson_lcdf,%
    poisson_log,%
    poisson_log_lpmf,%
    poisson_log_rng,%
    poisson_lpmf,%
    poisson_rng,%
    positive_infinity,%
    pow,%
    print,%
    prod,%
    qr_Q,%
    qr_R,%
    quad_form,%
    quad_form_diag,%
    quad_form_sym,%
    rank,%
    rayleigh,%
    rayleigh_cdf,%
    rayleigh_lccdf,%
    rayleigh_lcdf,%
    rayleigh_lpdf,%
    rayleigh_rng,%
    reject,%
    rep_array,%
    rep_matrix,%
    rep_row_vector,%
    rep_vector,%
    rising_factorial,%
    round,%
    row,%
    rows,%
    rows_dot_product,%
    rows_dot_self,%
    scaled_inv_chi_square,%
    scaled_inv_chi_square_cdf,%
    scaled_inv_chi_square_lccdf,%
    scaled_inv_chi_square_lcdf,%
    scaled_inv_chi_square_lpdf,%
    scaled_inv_chi_square_rng,%
    sd,%
    segment,%
    sin,%
    singular_values,%
    sinh,%
    size,%
    skew_normal,%
    skew_normal_cdf,%
    skew_normal_lccdf,%
    skew_normal_lcdf,%
    skew_normal_lpdf,%
    skew_normal_rng,%
    softmax,%
    sort_asc,%
    sort_desc,%
    sort_indices_asc,%
    sort_indices_desc,%
    sqrt,%
    sqrt2,%
    square,%
    squared_distance,%
    step,%
    student_t,%
    student_t_cdf,%
    student_t_lccdf,%
    student_t_lcdf,%
    student_t_lpdf,%
    student_t_rng,%
    sub_col,%
    sub_row,%
    sum,%
    tail,%
    tan,%
    tanh,%
    target,%
    tcrossprod,%
    tgamma,%
    to_array_1d,%
    to_array_2d,%
    to_matrix,%
    to_row_vector,%
    to_vector,%
    trace,%
    trace_gen_quad_form,%
    trace_quad_form,%
    trigamma,%
    trunc,%
    uniform,%
    uniform_cdf,%
    uniform_lccdf,%
    uniform_lcdf,%
    uniform_lpdf,%
    uniform_rng,%
    variance,%
    von_mises,%
    von_mises_lpdf,%
    von_mises_rng,%
    weibull,%
    weibull_cdf,%
    weibull_lccdf,%
    weibull_lcdf,%
    weibull_lpdf,%
    weibull_rng,%
    wiener,%
    wiener_lpdf,%
    wishart,%
    wishart_lpdf,%
    wishart_rng
  },%
  otherkeywords={.*=,./=,+=,-=,*=,/=,<-,~},%
  sensitive=true,%
  morecomment=[l]{\#},%
  morecomment=[l]{//},%
  morecomment=[n]{/*}{*/},%
  string=[d]"%,
  literate={<-}{{$\leftarrow$}}1 {~}{{$\sim$}}1%
}
%    \end{macrocode}

%
% \iffalse
%</package>
% \fi
%
% \Finale