Augment Export function to support custom number formattingDoes Mathematica support variable frame rate for any video format, in analogue of GIF-style “DisplayDurations”?Converting a notebook to plain text programmaticallyAutomatizing PSfrag exportTeXForm and large brackets (Biggl[ etc)Export Tube with VertexColors to 3DSIs there any way to export vector graphics with shading?Classifying images in mass with URLs and CSV fileExport plots to Word 2016 using EMF: Many solutions, but one open issueExport list of numbers as one column in a specified number formatcontrol symmetry property when exporting matrix as Matrix Market format .mtx
Scaling an object to change its key
Do details of my undergraduate title matter?
What is the precise meaning of "подсел на мак"?
Basic power tool set for Home repair and simple projects
A medieval book with a redhead girl as a main character who allies with vampires and werewolves against scientific opposition
I just entered the USA without passport control at Atlanta airport
Got a new frameset, don't know why I need this split ring collar?
How do I become a better writer when I hate reading?
I have found ports on my Samsung smart tv running a display service. What can I do with it?
How do I correctly reduce geometry on part of a mesh?
Using roof rails to set up hammock
How did the European Union reach the figure of 3% as a maximum allowed deficit?
How to avoid offending original culture when making conculture inspired from original
Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?
How to add a сolumn from one table to another?
Kelvin type connection
How do credit card companies know what type of business I'm paying for?
How to make a villain when your PCs are villains?
How "fast" do astronomical events occur?
...and then she held the gun
How can I ping multiple IP addresses at the same time?
What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?
How to prevent cables getting intertwined
I'm yearning in grey
Augment Export function to support custom number formatting
Does Mathematica support variable frame rate for any video format, in analogue of GIF-style “DisplayDurations”?Converting a notebook to plain text programmaticallyAutomatizing PSfrag exportTeXForm and large brackets (Biggl[ etc)Export Tube with VertexColors to 3DSIs there any way to export vector graphics with shading?Classifying images in mass with URLs and CSV fileExport plots to Word 2016 using EMF: Many solutions, but one open issueExport list of numbers as one column in a specified number formatcontrol symmetry property when exporting matrix as Matrix Market format .mtx
$begingroup$
It's a shame that the Export
framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm
arguments should be used to format real numbers?
As an example:
ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]
should produce:
"3,14"
export output-formatting customization number-form
$endgroup$
add a comment |
$begingroup$
It's a shame that the Export
framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm
arguments should be used to format real numbers?
As an example:
ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]
should produce:
"3,14"
export output-formatting customization number-form
$endgroup$
add a comment |
$begingroup$
It's a shame that the Export
framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm
arguments should be used to format real numbers?
As an example:
ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]
should produce:
"3,14"
export output-formatting customization number-form
$endgroup$
It's a shame that the Export
framework provides no support for custom formatting of real numbers. Is it possible to augment the framework so that a "NumberForm" option can be passed in that specifies what NumberForm
arguments should be used to format real numbers?
As an example:
ExportString[3.14159, "Text", "NumberForm"->3, NumberPoint->","]
should produce:
"3,14"
export output-formatting customization number-form
export output-formatting customization number-form
asked Jun 9 at 20:30
Carl WollCarl Woll
84.1k3107218
84.1k3107218
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Both Export
and ExportString
use the common function System`ConvertersDump`ExportInternal
to produce their output. In particular, any options that are fed to Export
and ExportString
will be present as an option to System`ConvertersDump`ExportInternal
. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm
to format real numbers, while the format "Text" uses ToString
with InputForm
to format real numbers. So, the following function modifies both CForm
and Real
so that custom formatting occurs:
System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
nf = Lookup[Flatten@opts, "NumberForm"],
With[args=Sequence@@nf,
Internal`InheritedBlock[CForm, Real,
Unprotect[Real,CForm];
CForm=OutputForm@linearNumberForm[#,args]&;
Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
]
] /; !MatchQ[nf, ]
]
linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
Replace[boxes,
TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
]
]
stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]
Examples:
ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]
"3,142"
"5.18780*10^49"
I haven't checked this code for a variety of NumberForm
options, so please try it out and let me know of any deficiencies.
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200027%2faugment-export-function-to-support-custom-number-formatting%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
$begingroup$
Both Export
and ExportString
use the common function System`ConvertersDump`ExportInternal
to produce their output. In particular, any options that are fed to Export
and ExportString
will be present as an option to System`ConvertersDump`ExportInternal
. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm
to format real numbers, while the format "Text" uses ToString
with InputForm
to format real numbers. So, the following function modifies both CForm
and Real
so that custom formatting occurs:
System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
nf = Lookup[Flatten@opts, "NumberForm"],
With[args=Sequence@@nf,
Internal`InheritedBlock[CForm, Real,
Unprotect[Real,CForm];
CForm=OutputForm@linearNumberForm[#,args]&;
Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
]
] /; !MatchQ[nf, ]
]
linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
Replace[boxes,
TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
]
]
stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]
Examples:
ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]
"3,142"
"5.18780*10^49"
I haven't checked this code for a variety of NumberForm
options, so please try it out and let me know of any deficiencies.
$endgroup$
add a comment |
$begingroup$
Both Export
and ExportString
use the common function System`ConvertersDump`ExportInternal
to produce their output. In particular, any options that are fed to Export
and ExportString
will be present as an option to System`ConvertersDump`ExportInternal
. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm
to format real numbers, while the format "Text" uses ToString
with InputForm
to format real numbers. So, the following function modifies both CForm
and Real
so that custom formatting occurs:
System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
nf = Lookup[Flatten@opts, "NumberForm"],
With[args=Sequence@@nf,
Internal`InheritedBlock[CForm, Real,
Unprotect[Real,CForm];
CForm=OutputForm@linearNumberForm[#,args]&;
Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
]
] /; !MatchQ[nf, ]
]
linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
Replace[boxes,
TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
]
]
stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]
Examples:
ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]
"3,142"
"5.18780*10^49"
I haven't checked this code for a variety of NumberForm
options, so please try it out and let me know of any deficiencies.
$endgroup$
add a comment |
$begingroup$
Both Export
and ExportString
use the common function System`ConvertersDump`ExportInternal
to produce their output. In particular, any options that are fed to Export
and ExportString
will be present as an option to System`ConvertersDump`ExportInternal
. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm
to format real numbers, while the format "Text" uses ToString
with InputForm
to format real numbers. So, the following function modifies both CForm
and Real
so that custom formatting occurs:
System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
nf = Lookup[Flatten@opts, "NumberForm"],
With[args=Sequence@@nf,
Internal`InheritedBlock[CForm, Real,
Unprotect[Real,CForm];
CForm=OutputForm@linearNumberForm[#,args]&;
Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
]
] /; !MatchQ[nf, ]
]
linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
Replace[boxes,
TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
]
]
stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]
Examples:
ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]
"3,142"
"5.18780*10^49"
I haven't checked this code for a variety of NumberForm
options, so please try it out and let me know of any deficiencies.
$endgroup$
Both Export
and ExportString
use the common function System`ConvertersDump`ExportInternal
to produce their output. In particular, any options that are fed to Export
and ExportString
will be present as an option to System`ConvertersDump`ExportInternal
. So, we can overload this function to enable customized processing of real numbers. There are at least two mechanisms by which the built-in code processes real numbers: The formats "Table", "CSV" and others use CForm
to format real numbers, while the format "Text" uses ToString
with InputForm
to format real numbers. So, the following function modifies both CForm
and Real
so that custom formatting occurs:
System`ConvertersDump`ExportInternal[channel_, expr_, format_List, opts___] := With[
nf = Lookup[Flatten@opts, "NumberForm"],
With[args=Sequence@@nf,
Internal`InheritedBlock[CForm, Real,
Unprotect[Real,CForm];
CForm=OutputForm@linearNumberForm[#,args]&;
Format[r_Real,InputForm]:=OutputForm@linearNumberForm[r,args];
System`ConvertersDump`ExportInternal[channel,expr,format,"NumberForm"->,opts]
]
] /; !MatchQ[nf, ]
]
linearNumberForm[e_, args__]:=With[boxes = ToBoxes[NumberForm[e, args]],
Replace[boxes,
TagBox[InterpretationBox[r_, ___],___]:>stringify[r]
]
]
stringify[s_String]:=If[StringMatchQ[s,""*""],StringTake[s,2,-2],s]
stringify[RowBox[s_]]:=StringJoin[Replace[s, x_:>stringify[x],1]]
stringify[SuperscriptBox[_, e_]]:="10^"<>stringify[e]
Examples:
ExportString[N@Pi, "Text", "NumberForm"->4, NumberPoint->","]
ExportString[(N@Pi)^100, "Text", "NumberForm"->5,5, NumberMultiplier->"*", ExponentFunction->(#&)]
"3,142"
"5.18780*10^49"
I haven't checked this code for a variety of NumberForm
options, so please try it out and let me know of any deficiencies.
answered Jun 9 at 21:01
Carl WollCarl Woll
84.1k3107218
84.1k3107218
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200027%2faugment-export-function-to-support-custom-number-formatting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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