2

I need to modify an argument of macro.
For example #4 equals to 1.1 Optimal solution of RNASP

When I write Figure #4, output is this:
Figure 1.1 Optimal solution of RNASP

But I need this:
Figure 1.1: Optimal solution of RNASP

I suppose I need some text operations like:

  • Split text to two. Figure number and text.
  • Add "Figure" word to start and ":" to end of the first part
  • Make first part bold
  • Combine first and second part and set as new variable to use in macro

Macro:

\def\@mymacro#1#2#3#4#5{
  ...
  \vskip 2cm
  Figure #4
  ...
}

Edit: I figured out that, for example in one instance #4 equals to the following string. I obtained it by making \detokenize{#4}

\hyper@linkstart {link}{\Hy@tocdestname }{\numberline {1.1}{\ignorespaces Optimal solution of RNASP.\relax }}\hyper@-linkend

When I make detokenize these functions work:

\StrLen{\detokenize{#4}}

\StrLeft{\detokenize{#4}}{30}

But this doesn't work:

\StrBetween{\detokenize{#4}}{foo}{bar}

Besides I need to put a : just after the figure number and make bold before the start of the caption.

Edit: Although having other class functions and definitions, I removed my other content and created an overleaf project. String manipulation can be seen on 206-208 of the gsu12.def file. https://www.overleaf.com/16674170vmvhjncqjndv

I get this error:
https://ibb.co/gZUn2d

5
  • Is this a purely abstract exercise, or is \@mymacro creating an instance of a figure float? If it's the latter, have you considered loading and using the caption package?
    – Mico
    Commented Jun 2, 2018 at 10:19
  • I'm trying to update List of figures and List of Tables. I have mentioned a detailed question here: tex.stackexchange.com/questions/434579/… I thought maybe it can be easier this way.
    – Mark
    Commented Jun 2, 2018 at 10:23
  • You can't modify #4 directly, but you can copy it into a macro and modify the macro. In this case, you might even need \newtoks. See also tex.stackexchange.com/questions/233085/…. Commented Jun 7, 2018 at 15:26
  • are you trying to hack into \l@figure or \@dottedtocline ? your overleaf code uses class gsufbe and many many packages so is not at all minimal. The crucial thing here is that your are using hyperref hence the decoration you saw with \detokenize.
    – user4686
    Commented Dec 1, 2018 at 11:30
  • in the case at than it appears you would only need to redefine locally \numberline to do what your want. But the question is too vague without indication of which macro exactly you are hacking into.
    – user4686
    Commented Dec 1, 2018 at 11:32

1 Answer 1

1

If you are using this to adjust figure captions, I would go with @Mico's suggestion and make use of the caption package. But, as an exercise on how to do this, one way is to use the xstring package and extract the string before and after the first space:

enter image description here

Code

\documentclass{article}
\usepackage{xstring}

\def\mymacro#1#2#3#4#5{%
    \StrBefore{#4}{ }[\FigNum]%
    \StrBehind{#4}{ }[\FigLabel]%
    \textbf{Figure \FigNum}:~\FigLabel%
}%

\begin{document}

\mymacro{}{}{}{1.1 Optimal solution of RNASP}{}

\end{document}
7
  • Thank you but I get some errors. For example \StrBefore{abcd efgh}{ }[\FigNum]% works well but \StrBefore{#4}{ }[\FigNum]% doesn't work. I get errors from .lof file. First error: Undefined control sequence for the line: \contentsline {figure}{\numberline {1.1}{\ignorespaces Optimal solution of RNASP.\relax }}{12}{figure.caption.11}
    – Mark
    Commented Jun 2, 2018 at 12:01
  • Does PDFLatex causes this problem ? I use PDFLatex to add width parameter like this: \includegraphics[width=6cm]{myfigure}. When I use XeLatex or LuaLatex, includegraphics give keyval error.
    – Mark
    Commented Jun 2, 2018 at 12:15
  • I added your string manipulation to the line of 206-208 of the gsu12.def file. You can see example project here: overleaf.com/16674170vmvhjncqjndv This is the error: ibb.co/gZUn2d
    – Mark
    Commented Jun 3, 2018 at 5:31
  • @Mark: Please compose a fully compilable MWE that reproduces the problem including the \documentclass and the appropriate packages. Remove anything that is not necessary to reproduce the problem and post that code in the question. If you are doing this for figure captions, you really should use a package such as caption. The above was to illustrate how you could do what you asked in the bullet points in the question. Commented Jun 3, 2018 at 7:16
  • I use this for table of figures. I updated my question after making a detokenize.
    – Mark
    Commented Jun 3, 2018 at 9:20

You must log in to answer this question.

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