Combining latex input and sedStore and retrieve content across documentsHow can I use input and include with...

Are there any sports for which the world's best player is female?

Machine learning and operations research projects

Multiple DUI convictions 12 years ago. Do I disclose if I know they will do a background check?

definition of "percentile"

Why are all my yellow 2V/20mA LEDs burning out with 330k Ohm resistor?

Why are Hobbits so fond of mushrooms?

Single word for "refusing to move to next activity unless present one is completed."

Credit score and financing new car

Why does the U.S. tolerate foreign influence from Saudi Arabia and Israel on its domestic policies while not tolerating that from China or Russia?

Cops: The Hidden OEIS Substring

Do you know your 'KVZ's?

QGIS Zanzibar how to crop?

Why isn't pressure filtration popular compared to vacuum filtration?

If your plane is out-of-control, why does military training instruct releasing the joystick to neutralize controls?

Ownership of a PhD Student's Research

How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?

Is there a way to know which symbolic expression mathematica used

Why doesn't sea level show seasonality?

Do I have a right to cancel a purchase of foreign currency in the UK?

Is a 10th-level Transmutation wizard considered a shapechanger for the purpose of effects such as Moonbeam?

Why weren't bootable game disks ever common on the IBM PC?

Has anyone in space seen or photographed a simple laser pointer from Earth?

For a hashing function like MD5, how similar can two plaintext strings be and still generate the same hash?

Would dual wielding daggers be a viable choice for a covert bodyguard?



Combining latex input and sed


Store and retrieve content across documentsHow can I use input and include with biblatex (biber backend)?Fit tables read in with input to page-widthLatex (XeTex) places equation parenthesis the wrong wayHow to input text from a fileLaTeX input from subfolders and subsubfoldersdisplay/print input filename at top of each page in draft modeHowto add batch section and input in a Latex documentUsing input to insert Tikz-code from another file: nested input cause wider border each time called?change the default path where Latex looks for everything






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







4















I need to include file, but I want to manipulate it directly from PDFLaTeX.
I must remove any text which is betweem { and }, including backslashes and parenthesis. I have tried many escaping options, but the best I could get it this and it is not working:



input{|"cat cxf.tex | sed 's|\{.*\}||g'"}


Is this possible at all?










share|improve this question







New contributor



meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to TeX.SE. Are you open to using LuaLaTeX instead of pdfLaTeX?

    – Mico
    10 hours ago


















4















I need to include file, but I want to manipulate it directly from PDFLaTeX.
I must remove any text which is betweem { and }, including backslashes and parenthesis. I have tried many escaping options, but the best I could get it this and it is not working:



input{|"cat cxf.tex | sed 's|\{.*\}||g'"}


Is this possible at all?










share|improve this question







New contributor



meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to TeX.SE. Are you open to using LuaLaTeX instead of pdfLaTeX?

    – Mico
    10 hours ago














4












4








4


1






I need to include file, but I want to manipulate it directly from PDFLaTeX.
I must remove any text which is betweem { and }, including backslashes and parenthesis. I have tried many escaping options, but the best I could get it this and it is not working:



input{|"cat cxf.tex | sed 's|\{.*\}||g'"}


Is this possible at all?










share|improve this question







New contributor



meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I need to include file, but I want to manipulate it directly from PDFLaTeX.
I must remove any text which is betweem { and }, including backslashes and parenthesis. I have tried many escaping options, but the best I could get it this and it is not working:



input{|"cat cxf.tex | sed 's|\{.*\}||g'"}


Is this possible at all?







input brackets






share|improve this question







New contributor



meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question







New contributor



meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question






New contributor



meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 10 hours ago









meolicmeolic

1212 bronze badges




1212 bronze badges




New contributor



meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




meolic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • Welcome to TeX.SE. Are you open to using LuaLaTeX instead of pdfLaTeX?

    – Mico
    10 hours ago



















  • Welcome to TeX.SE. Are you open to using LuaLaTeX instead of pdfLaTeX?

    – Mico
    10 hours ago

















Welcome to TeX.SE. Are you open to using LuaLaTeX instead of pdfLaTeX?

– Mico
10 hours ago





Welcome to TeX.SE. Are you open to using LuaLaTeX instead of pdfLaTeX?

– Mico
10 hours ago










2 Answers
2






active

oldest

votes


















5














This works for me (with pdflatex -shell-escape, of course) and prints just “abc”.



begin{filecontents*}{jobname-test.tex}
abc{def}
end{filecontents*}

documentclass{article}

begin{document}

input{|"cat jobname-test.tex | sed 's|string\{.*string\}||g'"}

end{document}


The issue is that TeX performs macro expansion on the argument to input; with string\ we nullify the macro nature of \.



I use jobname just for avoiding the risk of clobbering my files.



If you want a non-greedy replacement, it's a bit more complicated (you could use Perl, instead). The search string should be something like



\{[^\}]*\}


This can be more easily accomplished by defining the string beforehand:



begin{filecontents*}{jobname-test.tex}
abc{def}ghi{jkl}
end{filecontents*}

documentclass{article}

begin{document}

edefsearchstring{string\string{[^string\string}]*string\string}}
input{|"cat jobname-test.tex | sed 's|searchstring||g'"}

end{document}


In this case the output would by “abcghi”.






share|improve this answer





















  • 1





    +1 :) just wondered if the match might be .*? so as to be non-greedy?

    – cmhughes
    7 hours ago











  • @cmhughes As far as I know, sed doesn't support non-greedy search strings.

    – egreg
    7 hours ago



















4














Assuming you're free to use LuaLaTeX, and assuming further that the material between { and } (including the delimiters) is all on one line, the following solution should work just fine for you.



The solution consists of a Lua function (stored in an external file) and two LaTeX macros; the first assigns the Lua function to the process_input_buffer callback, making it act like a preprocessor, and the second removes the preprocessor-like operation of the Lua function.



enter image description here



The pattern-matching operation, "\{.-\}", uses .- rather than -* to match "zero or more instances of any character". Observe that using -* would be a mistake here, as it would make Lua perform a "greedy" match and thus inappropriately obliterate the middle substring, uvw.



RequirePackage{filecontents}
%% External file with "{ ... }" material
begin{filecontents*}{cxf.tex}
$abc {...} uvw { int_0^1 } xyz$

abc{ ... }uvw{ int_0^1 }xyz
end{filecontents*}

% Place the Lua code in a separate external file
begin{filecontents*}{external.lua}
function remove_braced_stuff ( s )
return ( s:gsub ( "\{.-\}" , "" ) )
end
end{filecontents*}

documentclass{article}
%% Load the Lua function from the external file
directlua{dofile("external.lua")}

%% Two utility LaTeX macros
newcommand{RemoveBracedStuff}{directlua{
luatexbase.add_to_callback ( "process_input_buffer" ,
remove_braced_stuff , "removestuff" )}}
newcommand{DontRemoveBracedStuff}{directlua{
luatexbase.remove_from_callback ( "process_input_buffer" ,
"removestuff" )}}

begin{document}
RemoveBracedStuff % Enable the Lua function
input cxf % Load the external file

DontRemoveBracedStuff % Disable the Lua function
%% remainder of document
end{document}





share|improve this answer




























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    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
    });


    }
    });






    meolic is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f499387%2fcombining-latex-input-and-sed%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    This works for me (with pdflatex -shell-escape, of course) and prints just “abc”.



    begin{filecontents*}{jobname-test.tex}
    abc{def}
    end{filecontents*}

    documentclass{article}

    begin{document}

    input{|"cat jobname-test.tex | sed 's|string\{.*string\}||g'"}

    end{document}


    The issue is that TeX performs macro expansion on the argument to input; with string\ we nullify the macro nature of \.



    I use jobname just for avoiding the risk of clobbering my files.



    If you want a non-greedy replacement, it's a bit more complicated (you could use Perl, instead). The search string should be something like



    \{[^\}]*\}


    This can be more easily accomplished by defining the string beforehand:



    begin{filecontents*}{jobname-test.tex}
    abc{def}ghi{jkl}
    end{filecontents*}

    documentclass{article}

    begin{document}

    edefsearchstring{string\string{[^string\string}]*string\string}}
    input{|"cat jobname-test.tex | sed 's|searchstring||g'"}

    end{document}


    In this case the output would by “abcghi”.






    share|improve this answer





















    • 1





      +1 :) just wondered if the match might be .*? so as to be non-greedy?

      – cmhughes
      7 hours ago











    • @cmhughes As far as I know, sed doesn't support non-greedy search strings.

      – egreg
      7 hours ago
















    5














    This works for me (with pdflatex -shell-escape, of course) and prints just “abc”.



    begin{filecontents*}{jobname-test.tex}
    abc{def}
    end{filecontents*}

    documentclass{article}

    begin{document}

    input{|"cat jobname-test.tex | sed 's|string\{.*string\}||g'"}

    end{document}


    The issue is that TeX performs macro expansion on the argument to input; with string\ we nullify the macro nature of \.



    I use jobname just for avoiding the risk of clobbering my files.



    If you want a non-greedy replacement, it's a bit more complicated (you could use Perl, instead). The search string should be something like



    \{[^\}]*\}


    This can be more easily accomplished by defining the string beforehand:



    begin{filecontents*}{jobname-test.tex}
    abc{def}ghi{jkl}
    end{filecontents*}

    documentclass{article}

    begin{document}

    edefsearchstring{string\string{[^string\string}]*string\string}}
    input{|"cat jobname-test.tex | sed 's|searchstring||g'"}

    end{document}


    In this case the output would by “abcghi”.






    share|improve this answer





















    • 1





      +1 :) just wondered if the match might be .*? so as to be non-greedy?

      – cmhughes
      7 hours ago











    • @cmhughes As far as I know, sed doesn't support non-greedy search strings.

      – egreg
      7 hours ago














    5












    5








    5







    This works for me (with pdflatex -shell-escape, of course) and prints just “abc”.



    begin{filecontents*}{jobname-test.tex}
    abc{def}
    end{filecontents*}

    documentclass{article}

    begin{document}

    input{|"cat jobname-test.tex | sed 's|string\{.*string\}||g'"}

    end{document}


    The issue is that TeX performs macro expansion on the argument to input; with string\ we nullify the macro nature of \.



    I use jobname just for avoiding the risk of clobbering my files.



    If you want a non-greedy replacement, it's a bit more complicated (you could use Perl, instead). The search string should be something like



    \{[^\}]*\}


    This can be more easily accomplished by defining the string beforehand:



    begin{filecontents*}{jobname-test.tex}
    abc{def}ghi{jkl}
    end{filecontents*}

    documentclass{article}

    begin{document}

    edefsearchstring{string\string{[^string\string}]*string\string}}
    input{|"cat jobname-test.tex | sed 's|searchstring||g'"}

    end{document}


    In this case the output would by “abcghi”.






    share|improve this answer















    This works for me (with pdflatex -shell-escape, of course) and prints just “abc”.



    begin{filecontents*}{jobname-test.tex}
    abc{def}
    end{filecontents*}

    documentclass{article}

    begin{document}

    input{|"cat jobname-test.tex | sed 's|string\{.*string\}||g'"}

    end{document}


    The issue is that TeX performs macro expansion on the argument to input; with string\ we nullify the macro nature of \.



    I use jobname just for avoiding the risk of clobbering my files.



    If you want a non-greedy replacement, it's a bit more complicated (you could use Perl, instead). The search string should be something like



    \{[^\}]*\}


    This can be more easily accomplished by defining the string beforehand:



    begin{filecontents*}{jobname-test.tex}
    abc{def}ghi{jkl}
    end{filecontents*}

    documentclass{article}

    begin{document}

    edefsearchstring{string\string{[^string\string}]*string\string}}
    input{|"cat jobname-test.tex | sed 's|searchstring||g'"}

    end{document}


    In this case the output would by “abcghi”.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 7 hours ago

























    answered 10 hours ago









    egregegreg

    754k90 gold badges1977 silver badges3316 bronze badges




    754k90 gold badges1977 silver badges3316 bronze badges








    • 1





      +1 :) just wondered if the match might be .*? so as to be non-greedy?

      – cmhughes
      7 hours ago











    • @cmhughes As far as I know, sed doesn't support non-greedy search strings.

      – egreg
      7 hours ago














    • 1





      +1 :) just wondered if the match might be .*? so as to be non-greedy?

      – cmhughes
      7 hours ago











    • @cmhughes As far as I know, sed doesn't support non-greedy search strings.

      – egreg
      7 hours ago








    1




    1





    +1 :) just wondered if the match might be .*? so as to be non-greedy?

    – cmhughes
    7 hours ago





    +1 :) just wondered if the match might be .*? so as to be non-greedy?

    – cmhughes
    7 hours ago













    @cmhughes As far as I know, sed doesn't support non-greedy search strings.

    – egreg
    7 hours ago





    @cmhughes As far as I know, sed doesn't support non-greedy search strings.

    – egreg
    7 hours ago













    4














    Assuming you're free to use LuaLaTeX, and assuming further that the material between { and } (including the delimiters) is all on one line, the following solution should work just fine for you.



    The solution consists of a Lua function (stored in an external file) and two LaTeX macros; the first assigns the Lua function to the process_input_buffer callback, making it act like a preprocessor, and the second removes the preprocessor-like operation of the Lua function.



    enter image description here



    The pattern-matching operation, "\{.-\}", uses .- rather than -* to match "zero or more instances of any character". Observe that using -* would be a mistake here, as it would make Lua perform a "greedy" match and thus inappropriately obliterate the middle substring, uvw.



    RequirePackage{filecontents}
    %% External file with "{ ... }" material
    begin{filecontents*}{cxf.tex}
    $abc {...} uvw { int_0^1 } xyz$

    abc{ ... }uvw{ int_0^1 }xyz
    end{filecontents*}

    % Place the Lua code in a separate external file
    begin{filecontents*}{external.lua}
    function remove_braced_stuff ( s )
    return ( s:gsub ( "\{.-\}" , "" ) )
    end
    end{filecontents*}

    documentclass{article}
    %% Load the Lua function from the external file
    directlua{dofile("external.lua")}

    %% Two utility LaTeX macros
    newcommand{RemoveBracedStuff}{directlua{
    luatexbase.add_to_callback ( "process_input_buffer" ,
    remove_braced_stuff , "removestuff" )}}
    newcommand{DontRemoveBracedStuff}{directlua{
    luatexbase.remove_from_callback ( "process_input_buffer" ,
    "removestuff" )}}

    begin{document}
    RemoveBracedStuff % Enable the Lua function
    input cxf % Load the external file

    DontRemoveBracedStuff % Disable the Lua function
    %% remainder of document
    end{document}





    share|improve this answer






























      4














      Assuming you're free to use LuaLaTeX, and assuming further that the material between { and } (including the delimiters) is all on one line, the following solution should work just fine for you.



      The solution consists of a Lua function (stored in an external file) and two LaTeX macros; the first assigns the Lua function to the process_input_buffer callback, making it act like a preprocessor, and the second removes the preprocessor-like operation of the Lua function.



      enter image description here



      The pattern-matching operation, "\{.-\}", uses .- rather than -* to match "zero or more instances of any character". Observe that using -* would be a mistake here, as it would make Lua perform a "greedy" match and thus inappropriately obliterate the middle substring, uvw.



      RequirePackage{filecontents}
      %% External file with "{ ... }" material
      begin{filecontents*}{cxf.tex}
      $abc {...} uvw { int_0^1 } xyz$

      abc{ ... }uvw{ int_0^1 }xyz
      end{filecontents*}

      % Place the Lua code in a separate external file
      begin{filecontents*}{external.lua}
      function remove_braced_stuff ( s )
      return ( s:gsub ( "\{.-\}" , "" ) )
      end
      end{filecontents*}

      documentclass{article}
      %% Load the Lua function from the external file
      directlua{dofile("external.lua")}

      %% Two utility LaTeX macros
      newcommand{RemoveBracedStuff}{directlua{
      luatexbase.add_to_callback ( "process_input_buffer" ,
      remove_braced_stuff , "removestuff" )}}
      newcommand{DontRemoveBracedStuff}{directlua{
      luatexbase.remove_from_callback ( "process_input_buffer" ,
      "removestuff" )}}

      begin{document}
      RemoveBracedStuff % Enable the Lua function
      input cxf % Load the external file

      DontRemoveBracedStuff % Disable the Lua function
      %% remainder of document
      end{document}





      share|improve this answer




























        4












        4








        4







        Assuming you're free to use LuaLaTeX, and assuming further that the material between { and } (including the delimiters) is all on one line, the following solution should work just fine for you.



        The solution consists of a Lua function (stored in an external file) and two LaTeX macros; the first assigns the Lua function to the process_input_buffer callback, making it act like a preprocessor, and the second removes the preprocessor-like operation of the Lua function.



        enter image description here



        The pattern-matching operation, "\{.-\}", uses .- rather than -* to match "zero or more instances of any character". Observe that using -* would be a mistake here, as it would make Lua perform a "greedy" match and thus inappropriately obliterate the middle substring, uvw.



        RequirePackage{filecontents}
        %% External file with "{ ... }" material
        begin{filecontents*}{cxf.tex}
        $abc {...} uvw { int_0^1 } xyz$

        abc{ ... }uvw{ int_0^1 }xyz
        end{filecontents*}

        % Place the Lua code in a separate external file
        begin{filecontents*}{external.lua}
        function remove_braced_stuff ( s )
        return ( s:gsub ( "\{.-\}" , "" ) )
        end
        end{filecontents*}

        documentclass{article}
        %% Load the Lua function from the external file
        directlua{dofile("external.lua")}

        %% Two utility LaTeX macros
        newcommand{RemoveBracedStuff}{directlua{
        luatexbase.add_to_callback ( "process_input_buffer" ,
        remove_braced_stuff , "removestuff" )}}
        newcommand{DontRemoveBracedStuff}{directlua{
        luatexbase.remove_from_callback ( "process_input_buffer" ,
        "removestuff" )}}

        begin{document}
        RemoveBracedStuff % Enable the Lua function
        input cxf % Load the external file

        DontRemoveBracedStuff % Disable the Lua function
        %% remainder of document
        end{document}





        share|improve this answer















        Assuming you're free to use LuaLaTeX, and assuming further that the material between { and } (including the delimiters) is all on one line, the following solution should work just fine for you.



        The solution consists of a Lua function (stored in an external file) and two LaTeX macros; the first assigns the Lua function to the process_input_buffer callback, making it act like a preprocessor, and the second removes the preprocessor-like operation of the Lua function.



        enter image description here



        The pattern-matching operation, "\{.-\}", uses .- rather than -* to match "zero or more instances of any character". Observe that using -* would be a mistake here, as it would make Lua perform a "greedy" match and thus inappropriately obliterate the middle substring, uvw.



        RequirePackage{filecontents}
        %% External file with "{ ... }" material
        begin{filecontents*}{cxf.tex}
        $abc {...} uvw { int_0^1 } xyz$

        abc{ ... }uvw{ int_0^1 }xyz
        end{filecontents*}

        % Place the Lua code in a separate external file
        begin{filecontents*}{external.lua}
        function remove_braced_stuff ( s )
        return ( s:gsub ( "\{.-\}" , "" ) )
        end
        end{filecontents*}

        documentclass{article}
        %% Load the Lua function from the external file
        directlua{dofile("external.lua")}

        %% Two utility LaTeX macros
        newcommand{RemoveBracedStuff}{directlua{
        luatexbase.add_to_callback ( "process_input_buffer" ,
        remove_braced_stuff , "removestuff" )}}
        newcommand{DontRemoveBracedStuff}{directlua{
        luatexbase.remove_from_callback ( "process_input_buffer" ,
        "removestuff" )}}

        begin{document}
        RemoveBracedStuff % Enable the Lua function
        input cxf % Load the external file

        DontRemoveBracedStuff % Disable the Lua function
        %% remainder of document
        end{document}






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 7 hours ago

























        answered 10 hours ago









        MicoMico

        296k32 gold badges410 silver badges808 bronze badges




        296k32 gold badges410 silver badges808 bronze badges






















            meolic is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            meolic is a new contributor. Be nice, and check out our Code of Conduct.













            meolic is a new contributor. Be nice, and check out our Code of Conduct.












            meolic is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to TeX - LaTeX 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.


            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%2ftex.stackexchange.com%2fquestions%2f499387%2fcombining-latex-input-and-sed%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

            Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

            The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

            Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...