2

I want to use the value of a flag imported from a datatool database (stored in an external .csv file) to enable (or disable) a beamer frame.

The .csv file is of the form:

\begin{filecontents*}{test.csv} 
test enable
test1 ok
test2 ok
test3 ok
\end{filecontents*}

Imported into a datatool database :

\DTLloaddb{test}{test.csv}

My command:

\newcommand{\frameIsEnabled}[1]{\ifstrequal{#1}{ok}{1}{0}}

I'm trying to use the \frameIsEnabled command to enable the frame fetching the database value:

\begin{frame}<presentation: \frameIsEnabled{\DTLfetch{test}{test1}{enable}}>

But latex is not happy. I suppose there is something wrong related to the format of the fetched value \DTLfetch{test}{test1}{enable}.

If I display it (i.e. in a table or text) it returns zero (i.e. the comparison with the string "ok" returns false).

Here's a minimal example to reproduce my problem.

Example 1, to verify the comparison of the "enable" flag with the string "ok":

\documentclass[6pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\mode<presentation>{\usetheme{Malmoe}}
\usepackage{datatool}
\usepackage{filecontents}

\begin{filecontents*}{test.csv} 
testName, enable
test1, ok
test2, ok
test3, ok
\end{filecontents*}

\newcommand{\frameIsEnabled}[1]{\ifstrequal{#1}{ok}{1}{0}}

\DTLloaddb[headers={testName, enable}]{testList}{test.csv}

\title{My Presentation}

\begin{document}
    \begin{frame}<presentation:1>
    Test1 enable flag is "\DTLfetch{testList}{testName}{test1}{enable}".

    Comparison with "ok" returns \frameIsEnabled{\DTLfetch{testList}{testName}{test1}{enable}}.
    \end{frame}
\end{document}

Within this code, the \frameIsEnabled command will return 0, while the desired output is 1

Example 2, using the fetched value from the database to enable the frame:

\documentclass[6pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\mode<presentation>{\usetheme{Malmoe}}
\usepackage{datatool}
\usepackage{filecontents}

\begin{filecontents*}{test.csv} 
testName, enable
test1, ok
test2, ok
test3, ok
\end{filecontents*}

\newcommand{\frameIsEnabled}[1]{\ifstrequal{#1}{ok}{1}{0}}

\DTLloaddb[headers={testName, enable}]{testList}{test.csv}

\title{My Presentation}

\begin{document}
    \begin{frame}<presentation:\frameIsEnabled{\DTLfetch{testList}{testName}{test1}{enable}}>
    Test1 enable flag is "\DTLfetch{testList}{testName}{test1}{enable}".

    Comparison with "ok" returns \frameIsEnabled{\DTLfetch{testList}{testName}{test1}{enable}}.
    \end{frame}
\end{document}

This code will throw the error:

Illegal parameter number in definition of \beamer@@@temp. \end{frame}
dsama
  • 23
  • Thank you very much for your answer / suggestion. I've edited my question with a code sample to reproduce the bug – dsama Jan 21 '19 at 22:54

1 Answers1

1

The problem is that the commands you use are not expandable. To worka round this problem one can combine https://tex.stackexchange.com/a/386503/36296 and https://tex.stackexchange.com/a/335489/36296

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage{graphicx}
\mode<presentation>{\usetheme{Malmoe}}
\usepackage{datatool}
\usepackage{filecontents}

\begin{filecontents*}{test.csv} 
testName, enable
test1, ok
test2, ok
test3, ok
\end{filecontents*}

\usepackage{xparse}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\xifstrequal}{mmmm}
 {
  \str_if_eq_x:nnTF { #1 } { #2 } { #3 } { #4 }
 }
\ExplSyntaxOff

\newcommand{\DTLfetchsave}[5]{%
  \edtlgetrowforvalue{#2}{\dtlcolumnindex{#2}{#3}}{#4}%
  \dtlgetentryfromcurrentrow{\dtlcurrentvalue}{\dtlcolumnindex{#2}{#5}}%
  \let#1\dtlcurrentvalue
}

\newcommand{\frameIsEnabled}[1]{\xifstrequal{#1}{ok}{1}{0}}

\DTLloaddb[headers={testName, enable}]{testList}{test.csv}

\title{My Presentation}

\begin{document}

\begin{frame}
content...
\end{frame}


\DTLfetchsave{\temp}{testList}{testName}{test1}{enable}%
\begin{frame}<presentation:\frameIsEnabled{\temp}>
    Test1 enable flag is "\DTLfetch{testList}{testName}{test1}{enable}".

\end{frame}
\end{document}