String manipulation for latex












0














I am trying to write a long expression with numbers and strings in a certain way so that it could be fed to latex. A short part of the expression is like



exp = 176*X*Y/9 + (1408*X*Y^2)/9 + 23/10 + ...


The desired output is



exp = X Y (frac{176}{9}) + X Y^2 (frac{1408}{9}) + frac{23}{10} + ...


While I know how to do for pure numbers like the last terms 23/10 (thanks to stackoverflow ), the cases where it is mixed with string is unclear.
The actual case is more complicated with more strings like Zeta[2], Log[p] etc., however a hint could be useful.










share|improve this question






















  • I am trying to write a long expression ... The desired output is. Just write the output then? Are you really trying to write a long expression? Or you are trying to write a bash script that will transform from one input to another? If you know how to do it for pure numbers, can you post some code how to it? What have you tried? You need to find the number not string in multiplication and use it to place inside the frac part. Have you read converting-c-into-latex?
    – Kamil Cuk
    Nov 19 at 21:46










  • why not write it as 176/9*X*Y ... ? So that you can trivially transform?
    – karakfa
    Nov 19 at 21:47












  • @KamilCuk Yes. I am trying to transform a long mathematica output into a latex form. I have mentioned that for pure numbers I found something like this: sed -E 's|([0-9]+)/([0-9]+)|\frac{1}{2}|g' file
    – Boogeyman
    Nov 19 at 21:54










  • @karakfa yes the cases 176/9*XY ... would be trivial with the above code. But my expression has different form like (176*XY)/9 from mathematica. I do not know now how to change that. However I will look at this.
    – Boogeyman
    Nov 19 at 21:57










  • So I would go with dynamic programming. Concentrate on creating a function which would convert a number*X*Y/number into X*Y*number/number. Are all expressions in the form you posted? Can they be grouped and parsed separately when using a + sign as a separator? If not, you are left with writing a very smart parser, which probably is simpler in mathematica then in bash.
    – Kamil Cuk
    Nov 19 at 22:22
















0














I am trying to write a long expression with numbers and strings in a certain way so that it could be fed to latex. A short part of the expression is like



exp = 176*X*Y/9 + (1408*X*Y^2)/9 + 23/10 + ...


The desired output is



exp = X Y (frac{176}{9}) + X Y^2 (frac{1408}{9}) + frac{23}{10} + ...


While I know how to do for pure numbers like the last terms 23/10 (thanks to stackoverflow ), the cases where it is mixed with string is unclear.
The actual case is more complicated with more strings like Zeta[2], Log[p] etc., however a hint could be useful.










share|improve this question






















  • I am trying to write a long expression ... The desired output is. Just write the output then? Are you really trying to write a long expression? Or you are trying to write a bash script that will transform from one input to another? If you know how to do it for pure numbers, can you post some code how to it? What have you tried? You need to find the number not string in multiplication and use it to place inside the frac part. Have you read converting-c-into-latex?
    – Kamil Cuk
    Nov 19 at 21:46










  • why not write it as 176/9*X*Y ... ? So that you can trivially transform?
    – karakfa
    Nov 19 at 21:47












  • @KamilCuk Yes. I am trying to transform a long mathematica output into a latex form. I have mentioned that for pure numbers I found something like this: sed -E 's|([0-9]+)/([0-9]+)|\frac{1}{2}|g' file
    – Boogeyman
    Nov 19 at 21:54










  • @karakfa yes the cases 176/9*XY ... would be trivial with the above code. But my expression has different form like (176*XY)/9 from mathematica. I do not know now how to change that. However I will look at this.
    – Boogeyman
    Nov 19 at 21:57










  • So I would go with dynamic programming. Concentrate on creating a function which would convert a number*X*Y/number into X*Y*number/number. Are all expressions in the form you posted? Can they be grouped and parsed separately when using a + sign as a separator? If not, you are left with writing a very smart parser, which probably is simpler in mathematica then in bash.
    – Kamil Cuk
    Nov 19 at 22:22














0












0








0







I am trying to write a long expression with numbers and strings in a certain way so that it could be fed to latex. A short part of the expression is like



exp = 176*X*Y/9 + (1408*X*Y^2)/9 + 23/10 + ...


The desired output is



exp = X Y (frac{176}{9}) + X Y^2 (frac{1408}{9}) + frac{23}{10} + ...


While I know how to do for pure numbers like the last terms 23/10 (thanks to stackoverflow ), the cases where it is mixed with string is unclear.
The actual case is more complicated with more strings like Zeta[2], Log[p] etc., however a hint could be useful.










share|improve this question













I am trying to write a long expression with numbers and strings in a certain way so that it could be fed to latex. A short part of the expression is like



exp = 176*X*Y/9 + (1408*X*Y^2)/9 + 23/10 + ...


The desired output is



exp = X Y (frac{176}{9}) + X Y^2 (frac{1408}{9}) + frac{23}{10} + ...


While I know how to do for pure numbers like the last terms 23/10 (thanks to stackoverflow ), the cases where it is mixed with string is unclear.
The actual case is more complicated with more strings like Zeta[2], Log[p] etc., however a hint could be useful.







bash sh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 21:39









Boogeyman

4511




4511












  • I am trying to write a long expression ... The desired output is. Just write the output then? Are you really trying to write a long expression? Or you are trying to write a bash script that will transform from one input to another? If you know how to do it for pure numbers, can you post some code how to it? What have you tried? You need to find the number not string in multiplication and use it to place inside the frac part. Have you read converting-c-into-latex?
    – Kamil Cuk
    Nov 19 at 21:46










  • why not write it as 176/9*X*Y ... ? So that you can trivially transform?
    – karakfa
    Nov 19 at 21:47












  • @KamilCuk Yes. I am trying to transform a long mathematica output into a latex form. I have mentioned that for pure numbers I found something like this: sed -E 's|([0-9]+)/([0-9]+)|\frac{1}{2}|g' file
    – Boogeyman
    Nov 19 at 21:54










  • @karakfa yes the cases 176/9*XY ... would be trivial with the above code. But my expression has different form like (176*XY)/9 from mathematica. I do not know now how to change that. However I will look at this.
    – Boogeyman
    Nov 19 at 21:57










  • So I would go with dynamic programming. Concentrate on creating a function which would convert a number*X*Y/number into X*Y*number/number. Are all expressions in the form you posted? Can they be grouped and parsed separately when using a + sign as a separator? If not, you are left with writing a very smart parser, which probably is simpler in mathematica then in bash.
    – Kamil Cuk
    Nov 19 at 22:22


















  • I am trying to write a long expression ... The desired output is. Just write the output then? Are you really trying to write a long expression? Or you are trying to write a bash script that will transform from one input to another? If you know how to do it for pure numbers, can you post some code how to it? What have you tried? You need to find the number not string in multiplication and use it to place inside the frac part. Have you read converting-c-into-latex?
    – Kamil Cuk
    Nov 19 at 21:46










  • why not write it as 176/9*X*Y ... ? So that you can trivially transform?
    – karakfa
    Nov 19 at 21:47












  • @KamilCuk Yes. I am trying to transform a long mathematica output into a latex form. I have mentioned that for pure numbers I found something like this: sed -E 's|([0-9]+)/([0-9]+)|\frac{1}{2}|g' file
    – Boogeyman
    Nov 19 at 21:54










  • @karakfa yes the cases 176/9*XY ... would be trivial with the above code. But my expression has different form like (176*XY)/9 from mathematica. I do not know now how to change that. However I will look at this.
    – Boogeyman
    Nov 19 at 21:57










  • So I would go with dynamic programming. Concentrate on creating a function which would convert a number*X*Y/number into X*Y*number/number. Are all expressions in the form you posted? Can they be grouped and parsed separately when using a + sign as a separator? If not, you are left with writing a very smart parser, which probably is simpler in mathematica then in bash.
    – Kamil Cuk
    Nov 19 at 22:22
















I am trying to write a long expression ... The desired output is. Just write the output then? Are you really trying to write a long expression? Or you are trying to write a bash script that will transform from one input to another? If you know how to do it for pure numbers, can you post some code how to it? What have you tried? You need to find the number not string in multiplication and use it to place inside the frac part. Have you read converting-c-into-latex?
– Kamil Cuk
Nov 19 at 21:46




I am trying to write a long expression ... The desired output is. Just write the output then? Are you really trying to write a long expression? Or you are trying to write a bash script that will transform from one input to another? If you know how to do it for pure numbers, can you post some code how to it? What have you tried? You need to find the number not string in multiplication and use it to place inside the frac part. Have you read converting-c-into-latex?
– Kamil Cuk
Nov 19 at 21:46












why not write it as 176/9*X*Y ... ? So that you can trivially transform?
– karakfa
Nov 19 at 21:47






why not write it as 176/9*X*Y ... ? So that you can trivially transform?
– karakfa
Nov 19 at 21:47














@KamilCuk Yes. I am trying to transform a long mathematica output into a latex form. I have mentioned that for pure numbers I found something like this: sed -E 's|([0-9]+)/([0-9]+)|\frac{1}{2}|g' file
– Boogeyman
Nov 19 at 21:54




@KamilCuk Yes. I am trying to transform a long mathematica output into a latex form. I have mentioned that for pure numbers I found something like this: sed -E 's|([0-9]+)/([0-9]+)|\frac{1}{2}|g' file
– Boogeyman
Nov 19 at 21:54












@karakfa yes the cases 176/9*XY ... would be trivial with the above code. But my expression has different form like (176*XY)/9 from mathematica. I do not know now how to change that. However I will look at this.
– Boogeyman
Nov 19 at 21:57




@karakfa yes the cases 176/9*XY ... would be trivial with the above code. But my expression has different form like (176*XY)/9 from mathematica. I do not know now how to change that. However I will look at this.
– Boogeyman
Nov 19 at 21:57












So I would go with dynamic programming. Concentrate on creating a function which would convert a number*X*Y/number into X*Y*number/number. Are all expressions in the form you posted? Can they be grouped and parsed separately when using a + sign as a separator? If not, you are left with writing a very smart parser, which probably is simpler in mathematica then in bash.
– Kamil Cuk
Nov 19 at 22:22




So I would go with dynamic programming. Concentrate on creating a function which would convert a number*X*Y/number into X*Y*number/number. Are all expressions in the form you posted? Can they be grouped and parsed separately when using a + sign as a separator? If not, you are left with writing a very smart parser, which probably is simpler in mathematica then in bash.
– Kamil Cuk
Nov 19 at 22:22












1 Answer
1






active

oldest

votes


















1














Mathematica function



TeXForm[exp]  


will give you the expression you need.






share|improve this answer





















  • TexForm is not very efficient when you try to convert a very long expression. Imagine part of the expression where numerator has a lots of frac{}{} and the whole numerator is divided by some small denominator. It will look horrible. I have already tried that. TexForm might be useful for simple small expressions but not for a a very huge and complicated expressions which I am encountering now.
    – Boogeyman
    Nov 19 at 22:04






  • 1




    Not sure what you mean, either the expression is complex and so is its latex representation or it can be simplified. If it can be simplified Mathematica can do it with Simplify[exp].
    – karakfa
    Nov 19 at 22:08










  • Unfortunately I can not post the full expression and I have only given a piece just to make it clear on what I want to do. I am talking about expressions with thousands of lines after simplification. TeXForm is not the right choice. Moreover I dont know how much of control one has while using TexForm. Meaning may be there could be fancy hack and a better way to use TeXForm!! Not sure. But my experience with just TexForm[expression] is not a good idea.
    – Boogeyman
    Nov 19 at 22:14






  • 1




    Sorry, expressions with thousands of lines is beyond my comprehension level. I would guess it should be for most of the other mortals as well. Good luck with your task!
    – karakfa
    Nov 19 at 22:18










  • I can give you links of scientific papers with such huge lines. But this is not the issue. Even with a few hundred lines or less TexForm is not good. Probably number/number*X*Y would be the best way to go!
    – Boogeyman
    Nov 19 at 22:36











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383021%2fstring-manipulation-for-latex%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Mathematica function



TeXForm[exp]  


will give you the expression you need.






share|improve this answer





















  • TexForm is not very efficient when you try to convert a very long expression. Imagine part of the expression where numerator has a lots of frac{}{} and the whole numerator is divided by some small denominator. It will look horrible. I have already tried that. TexForm might be useful for simple small expressions but not for a a very huge and complicated expressions which I am encountering now.
    – Boogeyman
    Nov 19 at 22:04






  • 1




    Not sure what you mean, either the expression is complex and so is its latex representation or it can be simplified. If it can be simplified Mathematica can do it with Simplify[exp].
    – karakfa
    Nov 19 at 22:08










  • Unfortunately I can not post the full expression and I have only given a piece just to make it clear on what I want to do. I am talking about expressions with thousands of lines after simplification. TeXForm is not the right choice. Moreover I dont know how much of control one has while using TexForm. Meaning may be there could be fancy hack and a better way to use TeXForm!! Not sure. But my experience with just TexForm[expression] is not a good idea.
    – Boogeyman
    Nov 19 at 22:14






  • 1




    Sorry, expressions with thousands of lines is beyond my comprehension level. I would guess it should be for most of the other mortals as well. Good luck with your task!
    – karakfa
    Nov 19 at 22:18










  • I can give you links of scientific papers with such huge lines. But this is not the issue. Even with a few hundred lines or less TexForm is not good. Probably number/number*X*Y would be the best way to go!
    – Boogeyman
    Nov 19 at 22:36
















1














Mathematica function



TeXForm[exp]  


will give you the expression you need.






share|improve this answer





















  • TexForm is not very efficient when you try to convert a very long expression. Imagine part of the expression where numerator has a lots of frac{}{} and the whole numerator is divided by some small denominator. It will look horrible. I have already tried that. TexForm might be useful for simple small expressions but not for a a very huge and complicated expressions which I am encountering now.
    – Boogeyman
    Nov 19 at 22:04






  • 1




    Not sure what you mean, either the expression is complex and so is its latex representation or it can be simplified. If it can be simplified Mathematica can do it with Simplify[exp].
    – karakfa
    Nov 19 at 22:08










  • Unfortunately I can not post the full expression and I have only given a piece just to make it clear on what I want to do. I am talking about expressions with thousands of lines after simplification. TeXForm is not the right choice. Moreover I dont know how much of control one has while using TexForm. Meaning may be there could be fancy hack and a better way to use TeXForm!! Not sure. But my experience with just TexForm[expression] is not a good idea.
    – Boogeyman
    Nov 19 at 22:14






  • 1




    Sorry, expressions with thousands of lines is beyond my comprehension level. I would guess it should be for most of the other mortals as well. Good luck with your task!
    – karakfa
    Nov 19 at 22:18










  • I can give you links of scientific papers with such huge lines. But this is not the issue. Even with a few hundred lines or less TexForm is not good. Probably number/number*X*Y would be the best way to go!
    – Boogeyman
    Nov 19 at 22:36














1












1








1






Mathematica function



TeXForm[exp]  


will give you the expression you need.






share|improve this answer












Mathematica function



TeXForm[exp]  


will give you the expression you need.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 22:00









karakfa

48k52738




48k52738












  • TexForm is not very efficient when you try to convert a very long expression. Imagine part of the expression where numerator has a lots of frac{}{} and the whole numerator is divided by some small denominator. It will look horrible. I have already tried that. TexForm might be useful for simple small expressions but not for a a very huge and complicated expressions which I am encountering now.
    – Boogeyman
    Nov 19 at 22:04






  • 1




    Not sure what you mean, either the expression is complex and so is its latex representation or it can be simplified. If it can be simplified Mathematica can do it with Simplify[exp].
    – karakfa
    Nov 19 at 22:08










  • Unfortunately I can not post the full expression and I have only given a piece just to make it clear on what I want to do. I am talking about expressions with thousands of lines after simplification. TeXForm is not the right choice. Moreover I dont know how much of control one has while using TexForm. Meaning may be there could be fancy hack and a better way to use TeXForm!! Not sure. But my experience with just TexForm[expression] is not a good idea.
    – Boogeyman
    Nov 19 at 22:14






  • 1




    Sorry, expressions with thousands of lines is beyond my comprehension level. I would guess it should be for most of the other mortals as well. Good luck with your task!
    – karakfa
    Nov 19 at 22:18










  • I can give you links of scientific papers with such huge lines. But this is not the issue. Even with a few hundred lines or less TexForm is not good. Probably number/number*X*Y would be the best way to go!
    – Boogeyman
    Nov 19 at 22:36


















  • TexForm is not very efficient when you try to convert a very long expression. Imagine part of the expression where numerator has a lots of frac{}{} and the whole numerator is divided by some small denominator. It will look horrible. I have already tried that. TexForm might be useful for simple small expressions but not for a a very huge and complicated expressions which I am encountering now.
    – Boogeyman
    Nov 19 at 22:04






  • 1




    Not sure what you mean, either the expression is complex and so is its latex representation or it can be simplified. If it can be simplified Mathematica can do it with Simplify[exp].
    – karakfa
    Nov 19 at 22:08










  • Unfortunately I can not post the full expression and I have only given a piece just to make it clear on what I want to do. I am talking about expressions with thousands of lines after simplification. TeXForm is not the right choice. Moreover I dont know how much of control one has while using TexForm. Meaning may be there could be fancy hack and a better way to use TeXForm!! Not sure. But my experience with just TexForm[expression] is not a good idea.
    – Boogeyman
    Nov 19 at 22:14






  • 1




    Sorry, expressions with thousands of lines is beyond my comprehension level. I would guess it should be for most of the other mortals as well. Good luck with your task!
    – karakfa
    Nov 19 at 22:18










  • I can give you links of scientific papers with such huge lines. But this is not the issue. Even with a few hundred lines or less TexForm is not good. Probably number/number*X*Y would be the best way to go!
    – Boogeyman
    Nov 19 at 22:36
















TexForm is not very efficient when you try to convert a very long expression. Imagine part of the expression where numerator has a lots of frac{}{} and the whole numerator is divided by some small denominator. It will look horrible. I have already tried that. TexForm might be useful for simple small expressions but not for a a very huge and complicated expressions which I am encountering now.
– Boogeyman
Nov 19 at 22:04




TexForm is not very efficient when you try to convert a very long expression. Imagine part of the expression where numerator has a lots of frac{}{} and the whole numerator is divided by some small denominator. It will look horrible. I have already tried that. TexForm might be useful for simple small expressions but not for a a very huge and complicated expressions which I am encountering now.
– Boogeyman
Nov 19 at 22:04




1




1




Not sure what you mean, either the expression is complex and so is its latex representation or it can be simplified. If it can be simplified Mathematica can do it with Simplify[exp].
– karakfa
Nov 19 at 22:08




Not sure what you mean, either the expression is complex and so is its latex representation or it can be simplified. If it can be simplified Mathematica can do it with Simplify[exp].
– karakfa
Nov 19 at 22:08












Unfortunately I can not post the full expression and I have only given a piece just to make it clear on what I want to do. I am talking about expressions with thousands of lines after simplification. TeXForm is not the right choice. Moreover I dont know how much of control one has while using TexForm. Meaning may be there could be fancy hack and a better way to use TeXForm!! Not sure. But my experience with just TexForm[expression] is not a good idea.
– Boogeyman
Nov 19 at 22:14




Unfortunately I can not post the full expression and I have only given a piece just to make it clear on what I want to do. I am talking about expressions with thousands of lines after simplification. TeXForm is not the right choice. Moreover I dont know how much of control one has while using TexForm. Meaning may be there could be fancy hack and a better way to use TeXForm!! Not sure. But my experience with just TexForm[expression] is not a good idea.
– Boogeyman
Nov 19 at 22:14




1




1




Sorry, expressions with thousands of lines is beyond my comprehension level. I would guess it should be for most of the other mortals as well. Good luck with your task!
– karakfa
Nov 19 at 22:18




Sorry, expressions with thousands of lines is beyond my comprehension level. I would guess it should be for most of the other mortals as well. Good luck with your task!
– karakfa
Nov 19 at 22:18












I can give you links of scientific papers with such huge lines. But this is not the issue. Even with a few hundred lines or less TexForm is not good. Probably number/number*X*Y would be the best way to go!
– Boogeyman
Nov 19 at 22:36




I can give you links of scientific papers with such huge lines. But this is not the issue. Even with a few hundred lines or less TexForm is not good. Probably number/number*X*Y would be the best way to go!
– Boogeyman
Nov 19 at 22:36


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383021%2fstring-manipulation-for-latex%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy