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

Mark
  • 95
  • 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 Jun 02 '18 at 10:19
  • I'm trying to update List of figures and List of Tables. I have mentioned a detailed question here: https://tex.stackexchange.com/questions/434579/making-bold-in-list-of-figures-and-list-of-tables I thought maybe it can be easier this way. – Mark Jun 02 '18 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 https://tex.stackexchange.com/questions/233085/basics-of-parsing?s=1|21.8509. – John Kormylo Jun 07 '18 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. –  Dec 01 '18 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. –  Dec 01 '18 at 11:32

1 Answers1

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}

Peter Grill
  • 223,288
  • 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 Jun 02 '18 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 Jun 02 '18 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: https://www.overleaf.com/16674170vmvhjncqjndv This is the error: https://ibb.co/gZUn2d – Mark Jun 03 '18 at 05: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.

    – Peter Grill Jun 03 '18 at 07:16
  • I use this for table of figures. I updated my question after making a detokenize. – Mark Jun 03 '18 at 09:20
  • @Mark: While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Jun 04 '18 at 03:27
  • I would love to include a minimal example here. But I can't copy paste cls and def files here due to the limitation on post length. Besides, my Latex knowledge is not so good to remove unnecessary parts in class and definition files. – Mark Jun 04 '18 at 07:45