Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to test in my template if a call of

\lstinputlisting[style=mystyle,...

or

\printglossary[style=mystyle,...

is valid or will fail because of an unkown style.

However I could no find out in the sty files how these styles are saved and checked.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

glossaries defines an internal macro named \@glsstyle@<style> for each style <style>.

In case of listings it's a little bit trickier than that. Basically listings defines a macro \lststy@<style>$ for each style. However, \lstdefinestyle has an undocumented optional argument whose purpose is not quite clear to me. \lstdefinestyle[foo]{mystyle} would define a macro \lststy@mystyle$foo. I have never seen a use case for the optional argument before, though, and my (very superficial) tests didn't reveal how to load such a style, anyway.

Maybe something like the following would work for you:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{listings,glossaries}

% ignore the optional argument:
\newcommand*\ifdeflststyle[1]{%
  \ifcsdef{lststy@#1$}}

\newcommand*\ifdefglsstyle[1]{%
  \ifcsdef{@glsstyle@#1}}

\begin{document}

\lstdefinestyle{mystyle}{}
\ifdeflststyle{mystyle}{true}{false}     % => true
\ifdeflststyle{myotherstyle}{true}{false}% => false

\ifdefglsstyle{list}{true}{false}   % => true
\ifdefglsstyle{mystyle}{true}{false}% => false
\newglossarystyle{mystyle}{}
\ifdefglsstyle{mystyle}{true}{false}% => true

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.