0

I am using the following code to print a list of all characters that say something in a given scene of a play-script.

\newcommand\sceneroles[2][Roles]{%
  \def\scenename{#2}%
  \textbf{#1}:%
  \Bind{?id}{rdf:type}{rl:role}{%
    % \GetVal prints the variable name,
    % \GetValProperty extracts property from the name
    % Set the default left time
    % use the real at:left if it has been set
    \IfProperty{\GetVal{?id}}{is:playsin#2}{%
        \GetValProperty{?id}{rl:name}, %
    }{}%
  }%
}

the problem is, that I cannot get rid of the last comma.

what should be printed is:

Roles: Romeo, Juliet

what is printed:

Roles: Romeo, Juliet,

4
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – DG'
    Commented Oct 5, 2020 at 20:32
  • Should we look in every package to find out where \GetValProperty and \Bind are defined and guess how you get Romeo and Juliet out of thin air?
    – egreg
    Commented Oct 5, 2020 at 22:05
  • By the way, there's no trace of \GetValProperty in TeX Live files.
    – egreg
    Commented Oct 5, 2020 at 22:09
  • Sorry, it's rdfdef from this other question a few years ago: tex.stackexchange.com/questions/473097/…
    – Tobi
    Commented Oct 6, 2020 at 12:11

1 Answer 1

1

Use this definition:

\newcommand\sceneroles[2][Roles]{%
  \def\scenename{#2}% Store scene names
  \def\namesep{\def\namesep{, }}% One cycle delay name separator
  \textbf{#1}:%
  \Bind{?id}{rdf:type}{rl:role}{%
    % \GetVal prints the variable name,
    % \GetValProperty extracts property from the name
    % Set the default left time
    % use the real at:left if it has been set
    \IfProperty{\GetVal{?id}}{is:playsin#2}{%
      \namesep\GetValProperty{?id}{rl:name}%
    }{}%
  }%
}

It uses a cunning (La)TeX trick.

1
  • What if the cycles are performed in a group?
    – egreg
    Commented Oct 6, 2020 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .