Macro: How to suppress Texclipse error











up vote
0
down vote

favorite
1












For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.



Due to unorthodox order of begin{figure} and end{figure} in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end. However, the code compiles with fine output.



How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?



documentclass{article}
usepackage{graphicx}
usepackage{xparse}

% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn

% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}

% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}

% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}

% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

ExplSyntaxOff

begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}









share|improve this question


















  • 1




    just put the code in mypic.sty and use usepackage{mypic} in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
    – David Carlisle
    Jul 6 at 6:54















up vote
0
down vote

favorite
1












For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.



Due to unorthodox order of begin{figure} and end{figure} in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end. However, the code compiles with fine output.



How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?



documentclass{article}
usepackage{graphicx}
usepackage{xparse}

% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn

% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}

% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}

% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}

% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

ExplSyntaxOff

begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}









share|improve this question


















  • 1




    just put the code in mypic.sty and use usepackage{mypic} in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
    – David Carlisle
    Jul 6 at 6:54













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.



Due to unorthodox order of begin{figure} and end{figure} in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end. However, the code compiles with fine output.



How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?



documentclass{article}
usepackage{graphicx}
usepackage{xparse}

% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn

% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}

% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}

% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}

% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

ExplSyntaxOff

begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}









share|improve this question













For easy and versatile integration of pictures and graphics in my documents I found a nice solution in this post 'newcommand for pictures'.



Due to unorthodox order of begin{figure} and end{figure} in the code I always have Texclipse (pdflatex, oxygen) showing errors at these lines (see code below}: begin{figure} does not have matching end; at least one unbalanced begin-end. However, the code compiles with fine output.



How can I avoid getting these error messages with the functionality of the code pointed out in the post? If the code is fine, how can I suppress the errors messages in Texclipse?



documentclass{article}
usepackage{graphicx}
usepackage{xparse}

% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn

% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}

% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}

% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}

% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

ExplSyntaxOff

begin{document}
An example picture is shown in ref{label}.
addpic{
placement=bp,
width=0.2,
options={angle=90},
image=example-image-a,
caption=Rotated image,
label=label,
shortcaption=In the text the image is rotated!,
}
end{document}






macros includegraphics eclipse






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 6 at 6:49









Stefan Bollmann

335213




335213








  • 1




    just put the code in mypic.sty and use usepackage{mypic} in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
    – David Carlisle
    Jul 6 at 6:54














  • 1




    just put the code in mypic.sty and use usepackage{mypic} in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
    – David Carlisle
    Jul 6 at 6:54








1




1




just put the code in mypic.sty and use usepackage{mypic} in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
– David Carlisle
Jul 6 at 6:54




just put the code in mypic.sty and use usepackage{mypic} in your docuemnt, then you can easily re-use in many documents and your editor will never see the code at all
– David Carlisle
Jul 6 at 6:54










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is



documentclass{article}
usepackage{addpic}
begin{document}
addpic{
width=0.3,
image=example-image,
caption={This is an example image, and a comma in the caption},
label=one,
}
end{document}


with the sty file containing



NeedsTeXFormat{LaTeX2e}
ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
RequirePackage{graphicx}
RequirePackage{xparse}

% Between the ExplSyntaxOn the code is copied from
% https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
ExplSyntaxOn

% the user level command
NewDocumentCommand{addpic}{m}
{
group_begin: % localize the changes to the variables
forthisdoc_pic:n { #1 }
group_end:
}

% the key-value interface
keys_define:nn { forthisdoc/pic }
{
placement .tl_set:N = l_forthisdoc_pic_placement_tl,
placement .initial:n = htp,
width .tl_set:N = l_forthisdoc_pic_width_tl,
width .initial:n = 1,
options .tl_set:N = l_forthisdoc_pic_options_tl,
image .tl_set:N = l_forthisdoc_pic_image_tl,
caption .tl_set:N = l_forthisdoc_pic_caption_tl,
shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
label .tl_set:N = l_forthisdoc_pic_label_tl,
}

% the main command
cs_new_protected:Nn forthisdoc_pic:n
{
% set the keys from the argument
keys_set:nn { forthisdoc/pic } { #1 }
% start the figure environment
__forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
centering
% include the image
__forthisdoc_pic_image:VVV
l_forthisdoc_pic_width_tl % the text width fraction
l_forthisdoc_pic_options_tl % other options
l_forthisdoc_pic_image_tl % the image name
% the caption
tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
{
caption{l_forthisdoc_pic_caption_tl}
}
{
caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
}
% the label
tl_if_empty:NF l_forthisdoc_pic_label_tl
{
label{l_forthisdoc_pic_label_tl}
}
% end the figure environment
end{figure}
}

% syntactic sugar: we want some token lists to be expanded before usage
cs_new_protected:Nn __forthisdoc_start_figure:n
{
begin{figure}[#1]
}
cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

cs_new_protected:Nn __forthisdoc_pic_image:nnn
{
includegraphics[width=#1textwidth,#2]{#3}
}
cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

ExplSyntaxOff


Here is some help for a good place of the sty file.






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',
    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f439467%2fmacro-how-to-suppress-texclipse-error%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








    up vote
    0
    down vote



    accepted










    As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is



    documentclass{article}
    usepackage{addpic}
    begin{document}
    addpic{
    width=0.3,
    image=example-image,
    caption={This is an example image, and a comma in the caption},
    label=one,
    }
    end{document}


    with the sty file containing



    NeedsTeXFormat{LaTeX2e}
    ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
    RequirePackage{graphicx}
    RequirePackage{xparse}

    % Between the ExplSyntaxOn the code is copied from
    % https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
    ExplSyntaxOn

    % the user level command
    NewDocumentCommand{addpic}{m}
    {
    group_begin: % localize the changes to the variables
    forthisdoc_pic:n { #1 }
    group_end:
    }

    % the key-value interface
    keys_define:nn { forthisdoc/pic }
    {
    placement .tl_set:N = l_forthisdoc_pic_placement_tl,
    placement .initial:n = htp,
    width .tl_set:N = l_forthisdoc_pic_width_tl,
    width .initial:n = 1,
    options .tl_set:N = l_forthisdoc_pic_options_tl,
    image .tl_set:N = l_forthisdoc_pic_image_tl,
    caption .tl_set:N = l_forthisdoc_pic_caption_tl,
    shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
    label .tl_set:N = l_forthisdoc_pic_label_tl,
    }

    % the main command
    cs_new_protected:Nn forthisdoc_pic:n
    {
    % set the keys from the argument
    keys_set:nn { forthisdoc/pic } { #1 }
    % start the figure environment
    __forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
    centering
    % include the image
    __forthisdoc_pic_image:VVV
    l_forthisdoc_pic_width_tl % the text width fraction
    l_forthisdoc_pic_options_tl % other options
    l_forthisdoc_pic_image_tl % the image name
    % the caption
    tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
    {
    caption{l_forthisdoc_pic_caption_tl}
    }
    {
    caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
    }
    % the label
    tl_if_empty:NF l_forthisdoc_pic_label_tl
    {
    label{l_forthisdoc_pic_label_tl}
    }
    % end the figure environment
    end{figure}
    }

    % syntactic sugar: we want some token lists to be expanded before usage
    cs_new_protected:Nn __forthisdoc_start_figure:n
    {
    begin{figure}[#1]
    }
    cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

    cs_new_protected:Nn __forthisdoc_pic_image:nnn
    {
    includegraphics[width=#1textwidth,#2]{#3}
    }
    cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

    ExplSyntaxOff


    Here is some help for a good place of the sty file.






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is



      documentclass{article}
      usepackage{addpic}
      begin{document}
      addpic{
      width=0.3,
      image=example-image,
      caption={This is an example image, and a comma in the caption},
      label=one,
      }
      end{document}


      with the sty file containing



      NeedsTeXFormat{LaTeX2e}
      ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
      RequirePackage{graphicx}
      RequirePackage{xparse}

      % Between the ExplSyntaxOn the code is copied from
      % https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
      ExplSyntaxOn

      % the user level command
      NewDocumentCommand{addpic}{m}
      {
      group_begin: % localize the changes to the variables
      forthisdoc_pic:n { #1 }
      group_end:
      }

      % the key-value interface
      keys_define:nn { forthisdoc/pic }
      {
      placement .tl_set:N = l_forthisdoc_pic_placement_tl,
      placement .initial:n = htp,
      width .tl_set:N = l_forthisdoc_pic_width_tl,
      width .initial:n = 1,
      options .tl_set:N = l_forthisdoc_pic_options_tl,
      image .tl_set:N = l_forthisdoc_pic_image_tl,
      caption .tl_set:N = l_forthisdoc_pic_caption_tl,
      shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
      label .tl_set:N = l_forthisdoc_pic_label_tl,
      }

      % the main command
      cs_new_protected:Nn forthisdoc_pic:n
      {
      % set the keys from the argument
      keys_set:nn { forthisdoc/pic } { #1 }
      % start the figure environment
      __forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
      centering
      % include the image
      __forthisdoc_pic_image:VVV
      l_forthisdoc_pic_width_tl % the text width fraction
      l_forthisdoc_pic_options_tl % other options
      l_forthisdoc_pic_image_tl % the image name
      % the caption
      tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
      {
      caption{l_forthisdoc_pic_caption_tl}
      }
      {
      caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
      }
      % the label
      tl_if_empty:NF l_forthisdoc_pic_label_tl
      {
      label{l_forthisdoc_pic_label_tl}
      }
      % end the figure environment
      end{figure}
      }

      % syntactic sugar: we want some token lists to be expanded before usage
      cs_new_protected:Nn __forthisdoc_start_figure:n
      {
      begin{figure}[#1]
      }
      cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

      cs_new_protected:Nn __forthisdoc_pic_image:nnn
      {
      includegraphics[width=#1textwidth,#2]{#3}
      }
      cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

      ExplSyntaxOff


      Here is some help for a good place of the sty file.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is



        documentclass{article}
        usepackage{addpic}
        begin{document}
        addpic{
        width=0.3,
        image=example-image,
        caption={This is an example image, and a comma in the caption},
        label=one,
        }
        end{document}


        with the sty file containing



        NeedsTeXFormat{LaTeX2e}
        ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
        RequirePackage{graphicx}
        RequirePackage{xparse}

        % Between the ExplSyntaxOn the code is copied from
        % https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
        ExplSyntaxOn

        % the user level command
        NewDocumentCommand{addpic}{m}
        {
        group_begin: % localize the changes to the variables
        forthisdoc_pic:n { #1 }
        group_end:
        }

        % the key-value interface
        keys_define:nn { forthisdoc/pic }
        {
        placement .tl_set:N = l_forthisdoc_pic_placement_tl,
        placement .initial:n = htp,
        width .tl_set:N = l_forthisdoc_pic_width_tl,
        width .initial:n = 1,
        options .tl_set:N = l_forthisdoc_pic_options_tl,
        image .tl_set:N = l_forthisdoc_pic_image_tl,
        caption .tl_set:N = l_forthisdoc_pic_caption_tl,
        shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
        label .tl_set:N = l_forthisdoc_pic_label_tl,
        }

        % the main command
        cs_new_protected:Nn forthisdoc_pic:n
        {
        % set the keys from the argument
        keys_set:nn { forthisdoc/pic } { #1 }
        % start the figure environment
        __forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
        centering
        % include the image
        __forthisdoc_pic_image:VVV
        l_forthisdoc_pic_width_tl % the text width fraction
        l_forthisdoc_pic_options_tl % other options
        l_forthisdoc_pic_image_tl % the image name
        % the caption
        tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
        {
        caption{l_forthisdoc_pic_caption_tl}
        }
        {
        caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
        }
        % the label
        tl_if_empty:NF l_forthisdoc_pic_label_tl
        {
        label{l_forthisdoc_pic_label_tl}
        }
        % end the figure environment
        end{figure}
        }

        % syntactic sugar: we want some token lists to be expanded before usage
        cs_new_protected:Nn __forthisdoc_start_figure:n
        {
        begin{figure}[#1]
        }
        cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

        cs_new_protected:Nn __forthisdoc_pic_image:nnn
        {
        includegraphics[width=#1textwidth,#2]{#3}
        }
        cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

        ExplSyntaxOff


        Here is some help for a good place of the sty file.






        share|improve this answer












        As David Carlisle pointed out, putting the code into a *.sty file does it. E.g. a working example is



        documentclass{article}
        usepackage{addpic}
        begin{document}
        addpic{
        width=0.3,
        image=example-image,
        caption={This is an example image, and a comma in the caption},
        label=one,
        }
        end{document}


        with the sty file containing



        NeedsTeXFormat{LaTeX2e}
        ProvidesPackage{addpic}[2018/12/03 addpic by tex.stackexchange example]
        RequirePackage{graphicx}
        RequirePackage{xparse}

        % Between the ExplSyntaxOn the code is copied from
        % https://tex.stackexchange.com/questions/242271/newcommand-for-pictures
        ExplSyntaxOn

        % the user level command
        NewDocumentCommand{addpic}{m}
        {
        group_begin: % localize the changes to the variables
        forthisdoc_pic:n { #1 }
        group_end:
        }

        % the key-value interface
        keys_define:nn { forthisdoc/pic }
        {
        placement .tl_set:N = l_forthisdoc_pic_placement_tl,
        placement .initial:n = htp,
        width .tl_set:N = l_forthisdoc_pic_width_tl,
        width .initial:n = 1,
        options .tl_set:N = l_forthisdoc_pic_options_tl,
        image .tl_set:N = l_forthisdoc_pic_image_tl,
        caption .tl_set:N = l_forthisdoc_pic_caption_tl,
        shortcaption .tl_set:N = l_forthisdoc_pic_shortcaption_tl,
        label .tl_set:N = l_forthisdoc_pic_label_tl,
        }

        % the main command
        cs_new_protected:Nn forthisdoc_pic:n
        {
        % set the keys from the argument
        keys_set:nn { forthisdoc/pic } { #1 }
        % start the figure environment
        __forthisdoc_start_figure:V l_forthisdoc_pic_placement_tl
        centering
        % include the image
        __forthisdoc_pic_image:VVV
        l_forthisdoc_pic_width_tl % the text width fraction
        l_forthisdoc_pic_options_tl % other options
        l_forthisdoc_pic_image_tl % the image name
        % the caption
        tl_if_empty:NTF l_forthisdoc_pic_shortcaption_tl
        {
        caption{l_forthisdoc_pic_caption_tl}
        }
        {
        caption[l_forthisdoc_pic_shortcaption_tl]{l_forthisdoc_pic_caption_tl}
        }
        % the label
        tl_if_empty:NF l_forthisdoc_pic_label_tl
        {
        label{l_forthisdoc_pic_label_tl}
        }
        % end the figure environment
        end{figure}
        }

        % syntactic sugar: we want some token lists to be expanded before usage
        cs_new_protected:Nn __forthisdoc_start_figure:n
        {
        begin{figure}[#1]
        }
        cs_generate_variant:Nn __forthisdoc_start_figure:n { V }

        cs_new_protected:Nn __forthisdoc_pic_image:nnn
        {
        includegraphics[width=#1textwidth,#2]{#3}
        }
        cs_generate_variant:Nn __forthisdoc_pic_image:nnn { VVV }

        ExplSyntaxOff


        Here is some help for a good place of the sty file.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 3 at 18:37









        Stefan Bollmann

        335213




        335213






























            draft saved

            draft discarded




















































            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.





            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%2ftex.stackexchange.com%2fquestions%2f439467%2fmacro-how-to-suppress-texclipse-error%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

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?