4

Please help me to find out, how to pass a value to a command, which has additional arguments enclosed in (...).

\usepackage{bibleref}
\usepackage{xstring}

\begin{document}
\bibleverse{Gen}(9:9)
\bibleverse{Gen}(\StrBehind{Gen 9:9}{Gen })
\end{document}

This gives an error:

! Paragraph ended before \@bibleverse was complete.
5

The assignment occurring within \StrBehind is not expandable and therefore cannot be passed directly to \bibleverse. Moreover, the argument captured by \bibleverse (internally) won't be split properly if not fully expanded. You need to store the value first, and then pass an expanded version to \bibleverse:

enter image description here

\documentclass{article}
\usepackage{bibleref,xstring}% http://ctan.org/pkg/{bibleref,xstring}
\begin{document}
\bibleverse{Gen}(9:9)

\StrBehind{Gen 9:9}{Gen }[\chapverse]
\expandafter\bibleverse\expandafter{\expandafter G\expandafter e\expandafter n\expandafter}\expandafter(\chapverse)
\end{document}

\StrBehind{<stringA>}{<stringB>}[<cmd>] stores whatever follows <stringB> in <stringA> in <cmd>. Appropriately-placed \expandafters ensure that \chapverse is expanded before parsing of the argument between parentheses of \bibleverse is performed.

3

If your aim is to be able to specify only \macro{Gen 9:9} and format it as if you had written \bibleverse{Gen}(9:9), then xstring is not needed:

\documentclass{article}
\usepackage{bibleref}

\makeatletter
\newcommand{\shortbibleverse}[1]{\@shortbibleverse#1\@nil}
\def\@shortbibleverse#1 #2\@nil{\bibleverse{#1}(#2)}
\makeatother

\begin{document}
\bibleverse{Gen}(9:9)

\shortbibleverse{Gen 9:9}
\end{document}

Rename \shortbibleverse to your liking.

The macro works by splitting the argument at the (first) space, passing what's before as the mandatory argument to \bibleverse and what's after as the optional argument in parentheses.

enter image description here

  • Thanks, but that was just a MWE. – pantlmn Jul 29 '13 at 12:19
  • I want to write something like bibleref-russian, and it will need a more detailed processing of the arguments. – pantlmn Jul 29 '13 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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