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
Was planting UN flag on Moon ever discussed?
Do you have to have figures when playing D&D?
How and why do references in academic papers work?
Diatonic chords of a pentatonic vs blues scale?
Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?
Breaking changes to eieio in Emacs 27?
YA book about blind creatures that live underground and take kid's eyes
Was Self-modifying-code possible just using BASIC?
Oil draining out shortly after turbo hose detached/broke
C++ logging library
What would be the way to say "just saying" in German? (Not the literal translation)
Extracting data from Plot
How to befriend someone who doesn't like to talk?
What STL algorithm can determine if exactly one item in a container satisfies a predicate?
I've been given a project I can't complete, what should I do?
Housemarks (superimposed & combined letters, heraldry)
What should I be wary of when insurer is taking a lot of time to decide whether car is repairable or a total loss?
Suppose leased car is totalled: what are financial implications?
Grep Match and extract
As easy as Three, Two, One... How fast can you go from Five to Four?
So a part of my house disappeared... But not because of a chunk resetting
Command of files and size
Why did Intel abandon unified CPU cache?
Do you really need a KDF when you have a PRF?
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 8 hours ago
Carl WollCarl Woll
83.3k3105216
83.3k3105216
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 7 hours ago
Carl WollCarl Woll
83.3k3105216
83.3k3105216
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