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 7802039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:08:16+00:00 2026-06-02T01:08:16+00:00

[UPDATED] This is my task – Converting a bunch of custom built LaTeX files

  • 0

[UPDATED]

This is my task – Converting a bunch of custom built LaTeX files to into InDesign. So my current method is: run the .tex files through a PHP script that changes the custom LaTeX codes to more generic TeX codes, then I’m using TeX2Word to convert them to .doc files, and then placing those into InDesign.

What I’m wanting to do with this preg_replace is convert a few of the TeX tags so they won’t be touched by TeX2Word, then I’ll be able to run a script in InDesign that changes the HTML-like tags to InDesign text frames, footnotes, variables and such.

[/UPDATED]

I have some text with LaTeX markup in it:

$newphrase = "\blockquote{\hspace*{.5em}Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Integer posuere erat a ante venenatis dapibus posuere
velit aliquet. Aenean lacinia bibendum nulla sed consectetur. Aenean
eu leo quam. Pellentesque ornare sem lacinia quam venenatis
vestibulum. Sed posuere consectetur est at lobortis. \note{Integer
posuere erat a ante venenatis dapibus posuere velit aliquet.
\textit{Vivamus} sagittis lacus vel augue laoreet rutrum faucibus
dolor auctor.}}";

What I want to do is remove \blockquote{...} and replace it with <div>...</div>

So I’ve tried a jillion different versions of this:

$regex = "#(blockquote){(.*)(})#";
$replace = "<div>$2</div>";
$newphrase = preg_replace($regex,$replace,$newphrase);

This is the output

\<div>\hspace*{.5em</div>Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Integer posuere erat a ante venenatis dapibus posuere
velit aliquet. Aenean lacinia bibendum nulla sed consectetur. Aenean
eu leo quam. Pellentesque ornare sem lacinia quam venenatis
vestibulum. Sed posuere consectetur est at lobortis. \note{Integer
posuere erat a ante venenatis dapibus posuere velit aliquet.
\textit{Vivamus} sagittis lacus vel augue laoreet rutrum faucibus
dolor auctor.}}";

The first problem with it is that it replaces everything from \blockquote{ to the first }.
When I want it to ignore the next } if there has been another { after the initial \blockquote{.

The next problem I’m having is with the \ I can’t seem to escape it! I’ve tried \\, /\\/, \\\, /\\\/, [\], [\\]. Nothing works! I’m sure it’s because I don’t understand how it really IS suposed to work.

So finally, This is what I want to end up with:

<div>\hspace*{.5em}Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Integer posuere erat a ante venenatis dapibus posuere
velit aliquet. Aenean lacinia bibendum nulla sed consectetur. Aenean
eu leo quam. Pellentesque ornare sem lacinia quam venenatis
vestibulum. Sed posuere consectetur est at lobortis. \note{Integer
posuere erat a ante venenatis dapibus posuere velit aliquet.
\textit{Vivamus} sagittis lacus vel augue laoreet rutrum faucibus
dolor auctor.}</div>";

I’m planning to make $regex & $replace into arrays, so I can replace things like \textit{Vivamus} with this <em>Vivamus</em>

Any guidance would be MUCH welcomed and appreciated!

  • 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-06-02T01:08:17+00:00Added an answer on June 2, 2026 at 1:08 am

    If you still want to do the conversion yourself, you can do it using multiple passes thru the string, replacing the inner elements first:

    $t = '\blockquote{\hspace*{.5em}Lorem ipsum dolor sit amet, consectetur
    adipiscing elit. Integer posuere erat a ante venenatis dapibus posuere
    velit aliquet. Aenean lacinia bibendum nulla sed consectetur. Aenean
    eu leo quam. Pellentesque ornare sem lacinia quam venenatis
    vestibulum. Sed posuere consectetur est at lobortis. \note{Integer
    posuere erat a ante venenatis dapibus posuere velit aliquet.
    \textit{Vivamus} sagittis lacus vel augue laoreet rutrum faucibus
    dolor auctor.}}';
    
    function hspace($m) { return "<br />"; }
    function textit($m) { return "<i>" . $m[1] . "</i>"; }
    function note($m) { return "<b>" . $m[1] . "</b>"; }
    function blockquote($m) { return "<quote>" .  $m[1] . "</quote>"; }
    
    while (true) {
      $newt = $t;
      $newt = preg_replace_callback("/\\\\hspace\\*\\{([^{}]*?)\\}/", "hspace", $newt);
      $newt = preg_replace_callback("/\\\\textit\\{([^{}]*?)\\}/", "textit", $newt);
      $newt = preg_replace_callback("/\\\\note\\{([^{}]*?)\\}/", "note", $newt);
      $newt = preg_replace_callback("/\\\\blockquote{([^{}]*?)\\}/", "blockquote", $newt);
    
      if ($newt == $t) break;
      $t = $newt;
    }
    
    echo $t;
    

    But of course, this might work for simple examples, but you cannot use this method to correctly parse the whole TeX format. Also it gets very ineffective for longer inputs.

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

Sidebar

Related Questions

I want to run a cron rake task every time a record is updated
My Task : Need to look for any new/updated files in particular directory of
Update: I updated this after doing some digging and realizing that this might be
Updated Question: $(this).attr(EmployeeId, 'A42345'); $.ajax({ type: POST, url: url, data: {EmployeeId: ' + id
Hey! Total CakePHP noob here. Updated at bottom / This is sort of a
-- This is an updated post, old post removed -- Suppose I have data
N.B THIS QUESTION HAS BEEN UPDATED, READ FURTHER DOWN Hi, I want to create
I have a table of frequently updated information. This is presented using a container
I have updated my symfony version to 2.0.12 version. But I have this error
Is there anything wrong with this code? My entity is not getting updated. public

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.