Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:41:31+00:00 2026-05-29T07:41:31+00:00

Is ist possible to make a (Perl or whatever running on Mac OS X)

  • 0

Is ist possible to make a (Perl or whatever running on Mac OS X) script that converts

\section{long text}
\sectionmark{short text}

to

\section[long text]{long text\sectionmark{short text}}

or alternative to

\section{long text}[short text]

I can’t ensure that there are no line breaks in the long text or if there is a break between \section and \sectionmark.

This question is related with a problem discussed here an TeX.SX.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:41:32+00:00Added an answer on May 29, 2026 at 7:41 am
    awk '/\\section{long text}/ { oldline=$0
                                  getline
                                  gsub("{","[",oldline)
                                  gsub("}","]",oldline) 
                                  print gensub("(.*)\\[(.*)\\]","\\1[\\2]{\\2","g",oldline) $0 "}"
                                  getline
                                }
         1' INPUTFILE
    

    Will do it for you if there are no line breaks in long text and there is no empty line between \section and \sectionmark. If you have any of those, you can still modify it.

    So to answer your question: yes it is possible.

    UPDATE

    Here is a working solution, with awk:

    awk '/\\section{/ { oldline=$0
                        if ( oldline ~ /}/ ) {
                            lt=gensub(".*{([^}]+)}.*","\\1","g",oldline)
                        } else {
                            lt=gensub(".*{(.*)","\\1","g",oldline) 
                            getline tmp
                            while ( tmp !~  "}" ) {
                                lt=lt "\n" tmp
                                getline tmp
                            }
                            lt=lt "\n" gensub("}.*","","g",tmp)
                        }
                        getline
                        while ( $0 !~ /\\sectionmark/ ) {
                            getline
                        }
                        printf("\\section[%s]{%s%s}\n",lt,lt,$0)
                        getline
                      }
         ! /\\section{/ { print }' INPUT_FILE
    

    Note: it does not handle if anything appears between long text} and \sectionmark e.g.:

    \section{long text}**THIS TEXT WILL BE SKIPPED!!**
    \sectionmark{short text}
    

    You can see it in ACTION HERE!

    If you want to get rid of then new lines in long text just replace every "\n" with a " " in the script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is ist possible to tell String.split(() function that it has to split only by
ist it possible to do a 10-fold cross-validation with svmmulticlass or do I have
Is ist possible to Start a Tomcat with Maven without stopping Tomcat after Maven
is it possible to insert the word that was found into the replace ?
Ist there a possibility to do something like that: int selected_value = Dialog(This dialog
I usually use StructureMap in v 2.5. I think that v2.0 ist compatible to
A short question for the PROs. Is it possible to use Zend_Auth_Adapter_DbTable with ZendX_Db_Adapter?
I noticed, that in [24.4.7] of the last C++-Std Doc N3291 max ist not
Ist there any better way to replace/wrap the h*tp://name.tld/request_url?parameter or h*tps://name.tld/request_url?parameter text in some
ist there a way to get a change notification if an attached property changed?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.